jeudi 5 mars 2015

How to instantiate an object to another class in the constructor of a class? C++


Is it possible to construct an object to class2 in the constructor of class1 that can be used in all the functions in class1?


EXAMPLE:



class c1 {

//Constructor for c1
c1() {

//Object to class c2 that I want to be able to use in all the c1 functions
c2 c2Object;

}

void randomFunction() {

c2Object.randomFunctioninC2();

}


}



Aucun commentaire:

Enregistrer un commentaire