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::OFilterStreambuf(3bobcat)					 ostream filtering				    FBB::OFilterStreambuf(3bobcat)

NAME
FBB::OFilterStreambuf - Base class for std::ostream filtering SYNOPSIS
#include <bobcat/ofilterstreambuf> Linking option: -lbobcat DESCRIPTION
The FBB::OFilterStreambuf class is a specialization of the std::streambuf class and can be used as a base class for classes implementing ostream-filtering. Ostream filtering is defined here as the process by which inserted characters are subject to processing before they are passed on to another (filtered) ostream object (or they may be rejected). The filtering may also result in inserting additional information into the filtered ostream. Chaining of filters is also possible: the filtered ostream may itself use an OFilterStreambuf to filter its received information before passing it on to yet another ostream. As OFilterStreambuf inherits from std::streambuf an OFilterStreambuf object can be used to provide an ostream object with a std::streambuf. Information inserted into such a stream travels the following route: o The information is converted to characters using the standard conversion facilities implemented by std::ostream objects. E.g., when inserting the value 123 this value is converted to the characters '1', '2' and '3', respectively. o Each of the characters is then offered (in turn) to the std::streambuf that is associated with the ostream object. In particular, the std::streambuf's overflow() member is called. o OFstreamBuf's default overflow() function ignores characters, but specializations can override overflow() to process the received characters ad lib. o A overriding overflow() function has access to the member OFstreambuf::out() which is a reference to the std::ostream receiving the filtered information. To implement a simple copy-filter (i.e., all characters are accepted as-is) a class must be derived from OFilterStreambuf providing an overriding implementation of overflow(), e.g., as follows: int DerivedClass::overflow(int ch) { out().put(ch); } Next this std::streambuf specialization can be associated with an ostream into which information to be `copy filtered' can be inserted (cf. the EXAMPLE section below). NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
std::streambuf CONSTRUCTORS
o OFilterStreambuf(): This constructor creates a OFilterStreambuf object without associating it with a destination (filtered) ostream. o OFilterStreambuf(char const *fname, openmode mode = std::ios::out): This constructor creates a OFilterStreambuf object and opens a private std::ofstream object whose filename is provided and that should receive the filtered information. o OFilterStreambuf(std::ostream &out): This constructor creates a OFilterStreambuf object and will insert any filtered information into the provided ostream object. The class's destructor closes the destination (filtered) stream (cf. the description of close() below). MEMBER FUNCTIONS
All members of std::ostreambuf are available, as FBB::OFilterStreambuf inherits from that class. In particular, derived classes should pro- vide their own implementation of int underflow(int ch) to implement any non-trivial filtering. o void close(): This member calls the streambuf::sync() member to flush any pending information to the destination (filtered) stream and then closes the destination stream. Note that the default sync() member performs no special actions but it can be overridden by derived classes to flush the destination stream just prior to its closing. o void open(char const *fname, openmode mode = std::ios::out): This member closes the current destination (filtered) std::ostream object and associates the OFilterStreambuf object with a private std::ofstream object whose filename is provided and that should receive subsequently filtered information. o void open(std::ostream &out): This member closes the current destination (filtered) std::ostream object and associates the OFilterStreambuf object with the pro- vided ostream object. PROTECTED MEMBER FUNCTION
o std::ostream &out() const: This member is available to derived classes to insert information into the destination (filtered) stream. EXAMPLE
#include <iostream> #include <cctype> #include <bobcat/ofilterstreambuf> class NoDigits: public FBB::OFilterStreambuf { public: int overflow(int ch) { if (not isdigit(ch)) out().put(ch); return ch; } int sync() { out() << flush; return 0; } }; using namespace FBB; using namespace std; int main() { NoDigits nod(cout); // no digits to cout ostream out(&nod); out << in.rdbuf(); // rm digits from cin return 0; } FILES
bobcat/ofilterstreambuf - 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::OFilterStreambuf(3bobcat)
All times are GMT -4. The time now is 11:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy