Sponsored Content
Top Forums Programming How to initialize an object with another object of different class? Post 302886051 by Corona688 on Wednesday 29th of January 2014 12:55:14 PM
Old 01-29-2014
Your 'operator B' doesn't quite work, so it can't convert.

Making an operator there is tricky, because A doesn't know what the contents of B are yet... So you just have to say that the function exists inside the class, then put the function definition after B is defined.

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();
};

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

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

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

A::operator B() {
        B smplb;
        return(smplb);
}

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


Last edited by Corona688; 01-29-2014 at 02:00 PM..
This User Gave Thanks to Corona688 For This Post:
 

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
Tcl_BooleanObj(3)					      Tcl Library Procedures						 Tcl_BooleanObj(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_NewBooleanObj, Tcl_SetBooleanObj, Tcl_GetBooleanFromObj - manipulate Tcl objects as boolean values SYNOPSIS
#include <tcl.h> Tcl_Obj * Tcl_NewBooleanObj(boolValue) Tcl_SetBooleanObj(objPtr, boolValue) int Tcl_GetBooleanFromObj(interp, objPtr, boolPtr) ARGUMENTS
int boolValue (in) Integer value used to initialize or set a boolean object. If the integer is nonzero, the boolean object is set to 1; otherwise the boolean object is set to 0. Tcl_Obj *objPtr (in/out) For Tcl_SetBooleanObj, this points to the object to be converted to boolean type. For Tcl_GetBooleanFro- mObj, this refers to the object from which to get a boolean value; if objPtr does not already point to a boolean object, an attempt will be made to convert it to one. Tcl_Interp *interp (in/out) If an error occurs during conversion, an error message is left in the interpreter's result object unless interp is NULL. int *boolPtr (out) Points to place where Tcl_GetBooleanFromObj stores the boolean value (0 or 1) obtained from objPtr. _________________________________________________________________ DESCRIPTION
These procedures are used to create, modify, and read boolean Tcl objects from C code. Tcl_NewBooleanObj and Tcl_SetBooleanObj will create a new object of boolean type or modify an existing object to have boolean type. Both of these procedures set the object to have the bool- ean value (0 or 1) specified by boolValue; if boolValue is nonzero, the object is set to 1, otherwise to 0. Tcl_NewBooleanObj returns a pointer to a newly created object with reference count zero. Both procedures set the object's type to be boolean and assign the boolean value to the object's internal representation longValue member. Tcl_SetBooleanObj invalidates any old string representation and, if the object is not already a boolean object, frees any old internal representation. Tcl_GetBooleanFromObj attempts to return a boolean value from the Tcl object objPtr. If the object is not already a boolean object, it will attempt to convert it to one. If an error occurs during conversion, it returns TCL_ERROR and leaves an error message in the inter- preter's result object unless interp is NULL. Otherwise, Tcl_GetBooleanFromObj returns TCL_OK and stores the boolean value in the address given by boolPtr. If the object is not already a boolean object, the conversion will free any old internal representation. Objects having a string representation equal to any of 0, false, no, or off have a boolean value 0; if the string representation is any of 1, true, yes, or on the boolean value is 1. Any of these string values may be abbreviated, and upper-case spellings are also acceptable. SEE ALSO
Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult KEYWORDS
boolean, boolean object, boolean type, internal representation, object, object type, string representation Tcl 8.0 Tcl_BooleanObj(3)
All times are GMT -4. The time now is 06:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy