Is there something wrong with the following in terms of syntax for the following scenario:
If I have class Foo and a class Foo1 and my class Foo has a private member of type Foo1:
.h file:
class Foo{
Foo1 *oFoo;
public:
Foo(Foo1 &Fooy);
}
.cc file:
Foo::Foo(Foo1 &Fooy){
oFoo = &Fooy;
}
Is the assignment in the above constructor legal? I am new to C++.
It should be
oFooinstead ofFoo, and the member should be initialized in an initializer list:Otherwise it’s fine. Consider making the constructor
explicitto prevent unwanted implicit casts.