I have a class inheriting from boost::noncopyable
; say, with header excerpt as follows:
class A : boost::noncopyable {
...
blah
...
private:
struct impl;
boost::scoped_ptr<impl> m_impl;
};
Then in one of the projects of my solution, I have a class (that also happens to inherit from boost::noncopyable
), one whose private members in an implementation detail is a reference to an object of type A, say, in the header excerpt:
class B : boost::noncopyable {
...
blah
...
private:
struct impl;
boost::scoped_ptr<impl> m_impl;
};
and in the implementation excerpt (cpp):
struct B::impl {
impl(A& a) : m_a(a) {}
set_A(A& a) {m_a = a;}
A& m_a;
...
}
B(A& a) : m_impl(new impl(a)) {}
...
Then in another project of my solution, I have a class C inheriting from B, say, with a header excerpt:
class C : public B {
...
blah;
...
private:
struct impl;
boost::scoped_ptr<impl> m_impl;
};
and in the implementation excerpt (cpp):
struct C::impl {
impl(A& a) : m_a(a) {}
void set_A(A& a) {m_a = a;}
A& m_a;
};
C(A &a) : B(a), m_impl(new impl(a)) {}
...
But when I try to build in MSVC++ 2008, I get the following error:
error C2248: 'boost::noncopyable_::noncopyable::operator =' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'
see declaration of 'boost::noncopyable_::noncopyable::operator ='
error C2248: 'boost::scoped_ptr<T>::operator =' : cannot access private member declared in class 'boost::scoped_ptr<T>' with T = A::impl
This diagnostic occurred in the compiler generated function 'A& A::operator =(const A&)'
The compiler only has an issue with C's set_A
function, not B's set_A
. Appreciate if anyone has any ideas on this and can shed some light? Thanks as always for your interest.
Edit:
To summarize, what I don't understand here is why the compiler is picky about when to apply the error regarding boost::noncopyable
. When I comment out the set_A(..)
function in class C, everything compiles OK. But when I keep it, it gives the error, whereas it doesn't have any problems with the same in class B. I also edited the error message above slightly to give more detail. I note here that it stated something about a compiler generated function. Could it be that this happened only with class C for some reason? Why?