Why C++ doesn't use the parent's class function? (C++ question)
-
Hey everybody. Here's a C++ question. I have 2 classes:
template
class A_template
{
public:
... other stuff ...void operator = (T* other){ _obj = other; }
protected:
T* _x;
};
//-----------------------------------------------
class B : public A_template
{
... some functions ...
};Now, the problem is that if I have the following line of code: C* x = CreateC(); B b; b = x; // <--- compiler returns that there is no possible conversion, but it does, in A ! what am I doing wrong?? Thanks a lot !!! :-)
-
Hey everybody. Here's a C++ question. I have 2 classes:
template
class A_template
{
public:
... other stuff ...void operator = (T* other){ _obj = other; }
protected:
T* _x;
};
//-----------------------------------------------
class B : public A_template
{
... some functions ...
};Now, the problem is that if I have the following line of code: C* x = CreateC(); B b; b = x; // <--- compiler returns that there is no possible conversion, but it does, in A ! what am I doing wrong?? Thanks a lot !!! :-)
Oh, and the definition of B is: class B : public A_template. :-)
-
Oh, and the definition of B is: class B : public A_template. :-)
-
assignment operator works like the constructor when it comes to inheritance. You should read more about this. Also read about:
using A<T>::operator =;
which should be placed in the declaration of BThanks :-) I read about what you said, and I understand why the copy assignment is not being derived, but I can't find anything about the "using A::operator =;". Can I tell c++ explicitly that I want to use the operator at the base class?
-
Thanks :-) I read about what you said, and I understand why the copy assignment is not being derived, but I can't find anything about the "using A::operator =;". Can I tell c++ explicitly that I want to use the operator at the base class?