Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2005

Tip: Looking for answers? Try searching our database.

[bug] typedefed base class not visible [VC8 RTM.050727-4200]

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fernando Cacciola - 03 Nov 2005 19:04 GMT
Hi people,

I'm testing

Microsoft Visual Studio 2005
Version 8.0.50727.42  (RTM.050727-4200)

with our code base.

I'm getting lots of errors on code that compiled fine in 7.1.
Most of it boils down to the following new compiler bug:

struct A
{
 int foo() const { return 1; }
};

struct B : A
{
 typedef A base ;
};

struct D : B
{
} ;

int main(int argc, char* argv[])
{
B b ;
D d ;
int r0 = b.base::foo();
int r1 = d.base::foo(); // error C2039: 'A' : is not a member of 'D'

return 0;
}

As you can see, vc8 can't see the type B::base, which is A, from D.

Worst.. I get the same error even if D is defined as:

struct D : B
{
 typedef B::base base ;
} ;

which explicitely redeclares B::base within D

I can of course do something like

struct D : B
{
 typedef B Base ;
} ;

and then change the client code from

d.base::foo()

to

d.Base::base::foo()

which compiles OK, but I'd really hate to need to refactor ALL client code..
any ideas?

TIA

Signature

Fernando Cacciola
SciSoft
http://fcacciola.50webs.com/

Tamas Demjen - 03 Nov 2005 19:27 GMT
> I'm getting lots of errors on code that compiled fine in 7.1.
> Most of it boils down to the following new compiler bug:
[quoted text clipped - 8 lines]
>   typedef A base ;
> };

I think the new compiler is right, 7.1 is wrong, and the problem is in
your code. You're doing private inheritance. By writing

struct B : A

you are essencially making foo() invisible. You should try

struct B : public A

Tom
Fernando Cacciola - 03 Nov 2005 19:36 GMT
> I think the new compiler is right, 7.1 is wrong, and the problem is in
> your code. You're doing private inheritance. By writing
>
> struct B : A
>
> you are essencially making foo() invisible.
No. Is public inheritance because B is struct, not a class.

Test the code in

http://www.comeaucomputing.com/tryitout/

to see it's well-formed.

Comeau C++ is-and has always been-the best reference for testing std
conformance.

Signature

Fernando Cacciola
SciSoft
http://fcacciola.50webs.com/

Tamas Demjen - 03 Nov 2005 23:36 GMT
> No. Is public inheritance because B is struct, not a class.

Sorry, you're right, I was way off. I should've tried it before posting.

I discovered a workaround, I don't know if it works for you though:

struct D : B
{
  typedef B base; // <-- add this line
} ;

Tom
Doug Harrison [MVP] - 03 Nov 2005 20:56 GMT
>Hi people,
>
[quoted text clipped - 33 lines]
>
>As you can see, vc8 can't see the type B::base, which is A, from D.

I think it's probably a bug, and you can report it here:

http://lab.msdn.microsoft.com/productfeedback/Default.aspx

Comeau does like it, a lot more than I'm liking trying to figure this out
from reading the standard, anyway. :)

>Worst.. I get the same error even if D is defined as:
>
[quoted text clipped - 22 lines]
>which compiles OK, but I'd really hate to need to refactor ALL client code..
>any ideas?

That's not the nicest syntax, so I'd have to wonder why you're doing things
this way. What happens if someone says d.foo() instead of d.base::foo()?
Would it be appropriate for B to bring A::foo into scope with a
using-declaration, so that if would overload with B::foo? If not, what
about introducing a forwarding function A_foo into B?

Signature

Doug Harrison
Visual C++ MVP

Fernando Cacciola - 03 Nov 2005 21:36 GMT
> I think it's probably a bug, and you can report it here:
>
> http://lab.msdn.microsoft.com/productfeedback/Default.aspx

OK. I'll do it.

>> d.Base::base::foo()
>>
[quoted text clipped - 7 lines]
> B::foo? If not, what about introducing a forwarding function A_foo
> into B?

Well, what I posted was a simplified version of the actual code.
Anyway, this comes from something that once ocurred to me to be a good
idea.. I'm not sure anymore it really is.. still, I used it a lot those days
and it just linger there in this rather old code base.

I needed a way to offer a form of "late friendship", that is, a way to give
class A access to parts of class B "reserved for friends", but without
having B know about A (mainly becasue of the limitations of real friendship
between template classes)
A solution is to hide the reserved part of B, but only partially:

Consider the follow as part of some framework (or class library):

struct A
{
 int foo() ;
}

class B : A
{
   typedef A door ;

 private:

   int foo() ;
} ;

Framework users don't ever deal with A, only with B (that's the type exposed
by and documented in the framework), so b.foo() is "private" to them.
The framework itself, OTOH, gains access to foo() through the special
syntax:  b.door::foo();

Of course, nothing prevents a framework user to "discover the door" and use
it, so the whole technique is probably just nonsense; but I have to live
with it now ;)

As you can see, the whole idea is to require the user code to explicitely
walk through the base class to get access to the "reserved" interface.

NOTE: FWIW, I discover this techique in the CGAL library www.cgal.org, is
not my invention.

Best

Signature

Fernando Cacciola
SciSoft
http://fcacciola.50webs.com/


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.