E
er
hi,
i'm wondering what is the role of A:
perator= below in doing:
Impl impl0(0);
A a0(impl0);
std::vector<A> vec;
vec.push_back(a0);
if i put it as private the compiler complains but if i put it as
public, the message "A:
perator=" does not appear. the message
"A::A(A&)" however does print. any suggestion appreciated. thanks!
class Impl{
public:
Impl(unsigned int i_):i(i_){};
private:
unsigned int i;
};
class A{
public:
A(Impl& impl_):impl(impl_){};
A(const A& a):impl(a.impl){std::cout<<"A::A(const
A&)"<<std::endl;};
A& operator=(const A& a);
A& operator=(const A& a);{//complain if private
std::cout<<"A:
perator="<<std::endl;//does not show
if(&a!=this){
throw
std::runtime_error("A:
perator=");
};
return *this;
};
private:
A();
Impl& impl;//Impl& instead of some_ptr<Impl> because i intend to
keep impl throughout lifetime of A. anything wrong with it?
};
i'm wondering what is the role of A:
Impl impl0(0);
A a0(impl0);
std::vector<A> vec;
vec.push_back(a0);
if i put it as private the compiler complains but if i put it as
public, the message "A:
"A::A(A&)" however does print. any suggestion appreciated. thanks!
class Impl{
public:
Impl(unsigned int i_):i(i_){};
private:
unsigned int i;
};
class A{
public:
A(Impl& impl_):impl(impl_){};
A(const A& a):impl(a.impl){std::cout<<"A::A(const
A&)"<<std::endl;};
A& operator=(const A& a);
A& operator=(const A& a);{//complain if private
std::cout<<"A:
if(&a!=this){
throw
std::runtime_error("A:
};
return *this;
};
private:
A();
Impl& impl;//Impl& instead of some_ptr<Impl> because i intend to
keep impl throughout lifetime of A. anything wrong with it?
};