By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

Microsoft says...

P: n/a
The documentation of Microsoft's latest C++ compiler version
(it's called ".NET 2005" or something that) says:

// QUOTE START
Summary of Compile-Time Breaking Changes

This topic summarizes the compile-time errors and
warnings that will now be issued on code that compiled
without errors or warnings prior to Visual C++ 2003.
However, some conformance-related, compile-time breaking
changes were introduced in Visual C++ 2005.

A protected member (n) can only be accessed through a
member function of a class (B) that inherits from the
class (A) of which it (n) is a member (C2247).

' identifier ' not accessible because ' class ' uses ' specifier ' to inherit
from ' class '

identifier is inherited from a class declared with private or protected access.

The following sample generates C2247:

// C2247.cpp
class A {
public:
int i;
};
class B : private A {}; // B inherits a private A
class C : public B {} c; // so even though C's B is public
int j = c.i; // C2247, i not accessible

// QUOTE END

So, are they telling the C++ programmers who have to use their product
that their new compiler now detects this error? And that all their old
versions of the last maybe 10 years did not detect this basic error?
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Uenal Mutlu wrote:
The documentation of Microsoft's latest C++ compiler version
(it's called ".NET 2005" or something that) says:

// QUOTE START
Summary of Compile-Time Breaking Changes

This topic summarizes the compile-time errors and
warnings that will now be issued on code that compiled
without errors or warnings prior to Visual C++ 2003.
However, some conformance-related, compile-time breaking
changes were introduced in Visual C++ 2005.

A protected member (n) can only be accessed through a
member function of a class (B) that inherits from the
class (A) of which it (n) is a member (C2247).

' identifier ' not accessible because ' class ' uses ' specifier ' to inherit
from ' class '

identifier is inherited from a class declared with private or protected access.

The following sample generates C2247:

// C2247.cpp
class A {
public:
int i;
};
class B : private A {}; // B inherits a private A
class C : public B {} c; // so even though C's B is public
int j = c.i; // C2247, i not accessible

// QUOTE END

So, are they telling the C++ programmers who have to use their product
that their new compiler now detects this error? And that all their old
versions of the last maybe 10 years did not detect this basic error?

VC++ 2003 with just

cl temp.cpp

doesn't compile it:
temp.cpp
temp.cpp(13) : error C2247: 'A::i' not accessible because 'B' uses 'private' to
inherit from 'A'
temp.cpp(4) : see declaration of 'A::i'
temp.cpp(6) : see declaration of 'B'
temp.cpp(2) : see declaration of 'A'


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #2

P: n/a

Uenal Mutlu wrote:
The documentation of Microsoft's latest C++ compiler version
(it's called ".NET 2005" or something that) says:

// QUOTE START
Summary of Compile-Time Breaking Changes

This topic summarizes the compile-time errors and
warnings that will now be issued on code that compiled
without errors or warnings prior to Visual C++ 2003.
However, some conformance-related, compile-time breaking
changes were introduced in Visual C++ 2005.

A protected member (n) can only be accessed through a
member function of a class (B) that inherits from the
class (A) of which it (n) is a member (C2247).

The following sample generates C2247:

// C2247.cpp
class A {
public:
int i;
};
class B : private A {}; // B inherits a private A
class C : public B {} c; // so even though C's B is public
int j = c.i; // C2247, i not accessible

// QUOTE END

So, are they telling the C++ programmers who have to use their product that their new compiler now detects this error? And that all their old versions of the last maybe 10 years did not detect this basic error?


No, they're not. You're reading it wrong. There are a number of access
checks. The breaking change refers to a specific case, which applies
only to protected. The sample is anoter case which generates the same
message. The sample doesn't even /use/ protected!

The not-so-basic error is IIRC:

class A {
protected:
int i;
};
class B : A {
void foo(A* that) {
this->i; // OK
that->i; // Not OK, C2247 in VC8
}
};

HTH,
Michiel Salters

Jul 23 '05 #3

P: n/a

"msalters" <Mi*************@logicacmg.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...
The not-so-basic error is IIRC:

class A {
protected:
int i;
};
class B : A {
void foo(A* that) {
this->i; // OK
that->i; // Not OK, C2247 in VC8
}
};


With VC++ 2005 Express Beta I get the same. Also
with Borland's CBX. I understand why that->i
doesn't work. Why does this->i work? B is derived
using private inheritance. Shouldn't that make this->i
inaccessible? If not, how does private inheritance work?
I admit that I've never used it but...
Jul 23 '05 #4

P: n/a
Duane Hebert wrote:
"msalters" <Mi*************@logicacmg.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...

The not-so-basic error is IIRC:

class A {
protected:
int i;
};
class B : A {
void foo(A* that) {
this->i; // OK
that->i; // Not OK, C2247 in VC8
}
};

With VC++ 2005 Express Beta I get the same. Also
with Borland's CBX. I understand why that->i
doesn't work. Why does this->i work? B is derived
using private inheritance. Shouldn't that make this->i
inaccessible? If not, how does private inheritance work?
I admit that I've never used it but...

Of course it should work, that's the whole point of making
it protected, the derived parts of the class can get at the
protected base parts.
Jul 23 '05 #5

P: n/a

Duane Hebert wrote:
"msalters" <Mi*************@logicacmg.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...
The not-so-basic error is IIRC:

class A {
protected:
int i;
};
class B : A {
void foo(A* that) {
this->i; // OK
that->i; // Not OK, C2247 in VC8
}
};


With VC++ 2005 Express Beta I get the same. Also
with Borland's CBX. I understand why that->i
doesn't work. Why does this->i work? B is derived
using private inheritance. Shouldn't that make this->i
inaccessible?


No. private inheritance makes the public and protected members of
A accesible to B, but not to C - even if C inherits from B. So,
even if C indirectly inherits from A it can't access the protected
members of A. B can still use its private bases just like its
private members. Private inheritance, like private members, do not
affect the class in which the private appears.

HTH,
Michiel Salters

Jul 23 '05 #6

P: n/a

"Ron Natalie" <ro*@sensor.com> wrote in message
news:42**********************@news.newshosting.com ...
Of course it should work, that's the whole point of making
it protected, the derived parts of the class can get at the
protected base parts.


Yep. I opened a book <g> Using private inheritance,
doesn't affect the relation between A and B but it makes
the public and protected members derived from A private
wrt any class deriving from B. That's the part that I forgot.

Jul 23 '05 #7

P: n/a

"msalters" <Mi*************@logicacmg.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
No. private inheritance makes the public and protected members of
A accesible to B, but not to C - even if C inherits from B. So,
even if C indirectly inherits from A it can't access the protected
members of A. B can still use its private bases just like its
private members. Private inheritance, like private members, do not
affect the class in which the private appears.


Yep. I looked in one of my books after I posted (should do that before -
sorry for the noise<g>)

Jul 23 '05 #8

P: n/a
Duane Hebert wrote:
Yep. I looked in one of my books after I posted (should do that before -
sorry for the noise<g>)

To make things easier to remember, you can say that private inheritance makes public and
protected members private, and protected inheritance makes them protected.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.