vendredi 5 avril 2019

C++ constructor parameter as object

In my project there is a below class kind of use case. on compiling the below code i get the below ERROR.

class shared

{
    public:
    shared()
     {

cout<<"class shared \n";

}

};

class test1
{      
  public:
  test1(shared obj){

   cout<<"class test1 \n";
   }  
};

class test2
{

    private:
    shared s_obj;
    test1 test1_obj(s_obj);  // Error statement 

};

int main()
{

    test2 b_obj;
    return 0;
}

ERROR : error: ‘s_obj’ is not a type test1 test1_obj(s_obj);

Aucun commentaire:

Enregistrer un commentaire