S
subramanian100in
Suppose 'Test' is a class:
class Test
{
public:
....
private:
Test& operator=(const Test& rhs)
{
cout << "Test:
perator=() called" << endl;
}
};
Suppose I create
Test obj;
vector<Test> v;
v.push_back(obj);
Here I get compilation error because Test:
perator=() is private (I
kept it as private ONLY for learning purpose). However if I keep
Test:
perator=() as public, then it is not called for
'v.push_back(obj)'.
My doubt is, why does the compiler give error when Test:
perator=()
is private though it is not needed for push_back() operation ?
Kindly clarify.
Thanks
V.Subramanian
class Test
{
public:
....
private:
Test& operator=(const Test& rhs)
{
cout << "Test:
}
};
Suppose I create
Test obj;
vector<Test> v;
v.push_back(obj);
Here I get compilation error because Test:
kept it as private ONLY for learning purpose). However if I keep
Test:
'v.push_back(obj)'.
My doubt is, why does the compiler give error when Test:
is private though it is not needed for push_back() operation ?
Kindly clarify.
Thanks
V.Subramanian