Operator=

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Base { Base* operator= (Derived<int>* x) };

template <typename T>
class Derived : public Base 
{
	private:
		T a;
				
	public:
		Derived (T x) { a = x; }
		void show() { cout << a; }
};

int main()
{
    vector<Base*> v(10);
    v.at(0) = new Derived<int> (8);
    /*/ the compiler does not use the = operator stated above but the default one ... why? /*/
}
Last edited on
Because you defined operator for class Base, but your vector contains pointers to Base.
Does the base* (pointer) belong to class Base?
No. It is two distinct types.
Therefore how to define an operator= for Base* ?

Edit: i understand, thanks for all =))
Last edited on
Topic archived. No new replies allowed.