Sponsored Content
Top Forums Programming How to initialize an object with another object of different class? Post 302886035 by techmonk on Wednesday 29th of January 2014 12:16:58 PM
Old 01-29-2014
How to initialize an object with another object of different class?

How to initialize an object of class say "A", with an object of type say "B".
The following code give the error message "error: conversion from âAâ to non-scalar type âBâ requested"
Code:
#include <iostream>
using namespace std;

class B;
class A{
 public:
  A() { cout <<"\nA()" << endl; }

  A(A& rhs) { cout <<"\nCopyCtr:A&" << endl; }

  A& operator=(A& rhs){ cout <<"\nAssignment: A&" << endl; }

  operator B(A &rhs){
    B smplb;
    return smplb;
  }

};

class B{
 public:
  B() { cout <<"\nB()" << endl; }

  B(B& rhs) { cout <<"\nCopyCtrB&" << endl; }

  B& operator=(B& rhs) { cout <<"\nAssignment: B&" << endl; }
};

int main(){
  A a;
  B b = a;
  return 0;
}

 

10 More Discussions You Might Find Interesting

1. Programming

create object

can we create an parametrize object to a class with the help of new operator if yes then how (0 Replies)
Discussion started by: ramneek
0 Replies

2. Programming

Object File Error

Hi, I've tried to compile a program I wrote with a Makefile, yet it returns an error: <<<test_log>>> itest_log.o /sr/local/bin/gcc -o test_log.o -I ../../../include -L ../../../lib -llog_mgr sh: itest_log.o: execute permission denied Error code 1 make: Fatal error: Command failed for... (3 Replies)
Discussion started by: Stevhp
3 Replies

3. Programming

mozilla object

hi this i tried for getting url form mozilla window. and also for getting mozilla object file. is there any plz tell the way. thanking u. ramesh (7 Replies)
Discussion started by: ramesh.jella
7 Replies

4. Shell Programming and Scripting

find string object

I have strings like "$AEUT_BIN/aeutut02.ksh $IFS_MACHINE $AEFA_CONTROL $MVS_CONTROL" I am looking for a way to find out how to obtain aeutut02.ksh from the above mentioned string in unix shell script. (1 Reply)
Discussion started by: phoenixV007
1 Replies

5. UNIX for Dummies Questions & Answers

Object reference not set to an instance of an object

I am new to PHP and UNIX. I am using Apache to do my testing on a Windows Vista machine. I am getting this error when I am trying to connect to a web service. I did a search and did not see any posts that pertain to this. Here is my function: <?php function TRECSend($a, $b, $c, $d,... (0 Replies)
Discussion started by: EddiRae
0 Replies

6. Programming

object creation

Hi, I was asked this question in interview.can you people please help me out in this. class A { int i; a() { i=10; cout << i; } } int main() { A a(); // what will be the program output } Thanks, Harika (3 Replies)
Discussion started by: harikamamidala
3 Replies

7. Programming

sizeof(object) in C++

Hi, I have defined the class and call the sizeof(object to class) to get the size. # include <iostream> # include <iomanip> using namespace std; class sample { private: int i; float j; char k; public: sample() { } (2 Replies)
Discussion started by: ramkrix
2 Replies

8. Red Hat

shared object

Hi, I would like to create a shared object ( .so). This shared object 1. uses the functions from a library. 2. Also it should be able to use the global variable in an app To achieve this what should I do ? 1) To use the functions in the library should I give the -ld option while... (1 Reply)
Discussion started by: rvan
1 Replies

9. Programming

passing object to function, columns class

I am working on a small columns class, since I use allot of tabular data. I am trying to set up code to allow me to efficiently read in tabular data, manipulate it, and write to output files. I more or less know what I need to do, but there are many options to sort through. I have the beginnings... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

10. UNIX and Linux Applications

opends- help with custom object class

we have 2.2.0 of opends running on RedHat 2.6.21 and we're trying to setup a structure that will suit our needs. One of the things we'd like to do is create our own custom object classes based off some of the existing ones you get out of the box. The opends documentation covers this here (sorry, it... (1 Reply)
Discussion started by: snafu
1 Replies
FBB::MultiStreambuf(3bobcat)				     Writing multiple streams				      FBB::MultiStreambuf(3bobcat)

NAME
FBB::MultiStreambuf - Selectively writes multiple streams SYNOPSIS
#include <bobcat/multistreambuf> Linking option: -lbobcat DESCRIPTION
The FBB::MultiStreambuf class is a specialization of std::streambuf. It can be used to write selectvely to multiple std::ostreams. Each std::ostream that is associated with an FBB::MultiStreambuf is given a mode-tag indicating whether the stream should always be used when information is inserted into the FBB::MultiStreambuf, just once, or not at all. Each of the stream's mode-tags may be set to any of the defined tag-values. When the address of a FBB::MultiStreambuf is used to initialize a std::ostream the constructed std::ostream becomes an output-multiplexer: by inserting information into the std::ostream object, all std::ostream objects added to its FBB::MultiStreambuf buffer which have an active mode will receive that information. An FBB::MultiStreambuf object should be outlived by all active streams that are associated with it. No assumptions should be made about the order in which the std::ostream objects that are associated with the FBB::MultiStreambuf objects are visited when information is inserted. NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
std::streambuf ENUMERATION
In the Mode enumeration the following values are defined: o OFF: A std::ostream having this mode will not be used when information is inserted into an FBB::MultiStreambuf o ON: A std::ostream having this mode will be used when information is inserted into an FBB::MultiStreambuf o ONCE: A std::ostream having this mode will be used once, until the next flushing operation, when information is inserted into an FBB::Mul- tiStreambuf o RESET: A std::ostream having this mode will not be used when information is inserted into an FBB::MultiStreambuf. At a flush operation all ONCE modes will be set to RESET TYPES
The following subtypes are defined in the class FBB:MultiStreambuf: o iterator: This is a synonym of std::vector<stream>::iterator o const_iterator: This is a synonym of std::vector<stream>::const_iterator NESTED CLASS
The class FBB::MultiStreambuf::stream is defined as a nested class of FBB::MultiStreambuf. It offers the following constructor and public members: o stream(std::ostream &os, Mode mode = ON): The constructor stores a std::ostream object, and associates a Mode value with it. o void setMode(Mode mode): This member is used to redefine the stream's Mode value. o void mode() const: This member returns the stream's Mode value. o operator std::ostream &(): This member returns the stream's std::ostream. CONSTRUCTORS
o MultiStreambuf(): The default constructor creates a FBB::MultiStreambuf object which contains no associated std::ostream objects. o MultiStreambuf(std::ostream &os, Mode mode = ON): This constructor creates a FBB::MultiStreambuf object which is immediately associated with the std::ostream specified as its first argument. o MultiStreambuf(std::vector<MultiStreambuf::stream> const &osvector): This constructor creates a FBB::MultiStreambuf object which is immediately associated with all std::ostream objects that are stored in the MultiStreambuf::stream elements of the specified vector. The copy constructor is available. MEMBER FUNCTIONS
All members of std::ostringstream and std::exception are available, as FBB::MultiStreambuf inherits from these classes. o iterator begin(): This member returns an iterator to the first stream element that is stored in a FBB::MultiStreambuf object. o const_iterator begin(): This member returns an iterator to the first (unmodifiable) stream element that is stored in a FBB::MultiStreambuf object. o iterator end(): This member returns an iterator pointing beyond the last stream element that is stored in a FBB::MultiStreambuf object. o iterator end(): This member returns an iterator pointing beyond the last (unmodifiable) stream element that is stored in a FBB::MultiStreambuf object. o void insert(std::ostream &os, Mode mode = ON): This member adds the specified std::ostream using the specified Mode to the current set of stream objects. o void insert(std::vector<stream> const &os): This member adds all stream objects stored in the os vector to the current set of stream objects. o void void setOnce(): This member will reset all the RESET Mode values of the stored stream objects to ONCE. PROTECTED MEMBER FUNCTION
The member listed in this section implements the tasks of the comparably named virtual function in the class's private interface. This sep- arates the redefinable interface from the user-interface. The class MultiStreamBuf can, in accordance with Liskov's Substitution Principle, be used as a std:streambuf; but it also offers a facility for classes deriving from MultiStreamBuf. This facility is listed here. o int pSync(): The contents of the MultiStreamBuf's internal buffer is written to each of the std::ostream objects to which the MultiStreamBuf object has access. EXAMPLE
#include <iostream> #include <fstream> #include <bobcat/multistreambuf> using namespace std; using namespace FBB; int main() { MultiStreambuf msb(cout); ostream os(&msb); ofstream out("out"); msb.insert(out, MultiStreambuf::ONCE); os << "This is on cout and out" << endl; os << "This is on cout only" << endl; msb.setOnce(); os << "This is on cout and out" << endl; os << "This is on cout only" << endl; return 0; } FILES
bobcat/multistreambuf - defines the class interface SEE ALSO
bobcat(7) BUGS
None Reported. DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature; o bobcat_3.01.00-x.tar.gz: source archive; o bobcat_3.01.00-x_i386.changes: change log; o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location; BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::MultiStreambuf(3bobcat)
All times are GMT -4. The time now is 02:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy