473,508 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
--
Fernando Cacciola
SciSoft
http://fcacciola.50webs.com/
Nov 17 '05 #1
5 1197
Fernando Cacciola wrote:
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 ;
};


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
Nov 17 '05 #2
Tamas Demjen wrote:
Fernando Cacciola wrote:

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.

--
Fernando Cacciola
SciSoft
http://fcacciola.50webs.com/
Nov 17 '05 #3
On Thu, 3 Nov 2005 15:04:08 -0300, "Fernando Cacciola"
<fe***************@hotmail.com> wrote:
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.
I think it's probably a bug, and you can report it here:

http://lab.msdn.microsoft.com/produc...k/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:

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?


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?

--
Doug Harrison
Visual C++ MVP
Nov 17 '05 #4
Doug Harrison [MVP] wrote:
On Thu, 3 Nov 2005 15:04:08 -0300, "Fernando Cacciola"
<fe***************@hotmail.com> wrote:

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

http://lab.msdn.microsoft.com/produc...k/Default.aspx


OK. I'll do it.

d.Base::base::foo()

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?


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

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

Nov 17 '05 #5
Fernando Cacciola wrote:
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
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2065
by: Bengt Richter | last post by:
Peculiar boundary cases: >>> 2.0**31-1.0 2147483647.0 >>> int(2147483647.0) 2147483647L >>> int(2147483647L ) 2147483647 >>> >>> -2.0**31
9
3937
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
19
3545
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and...
35
2134
by: Maxim Yegorushkin | last post by:
The following code: #include <iostream> class base { private: virtual ~base() { std::cout << "virtual ~base()\n";
9
3121
by: Lonewolf | last post by:
Hi everyone.. I was trying to implement callback fucntions in native codes in my VC8 class, and referred to some online codes which use native class nested within managed class. basically of the...
0
2543
by: Shadow Lynx | last post by:
When using ASP.NET 2.0's built-in TreeView on a page with <BASE target = "AnythingBut_Self"></BASE> in the HEAD, the expand/collapse buttons fail to function. The reason for this is that the...
14
2303
by: Gaijinco | last post by:
I used C for a long time where I could open a file for input but if the file didn't existed, then I redirected the input to the standard input, something like: FILE *id=fopen("data.in","r"); ...
7
4247
by: Yuanfei | last post by:
Hi There, I just found that there is a problem in vc2005 regarding to time_t and localtime. See code snippets belows. Using this code segment, I found that when ut is 86200, the corresponding...
4
1411
by: miaohua1982 | last post by:
the programme is as follows #include <iostream> using namespace std; void f( const char*p){cout<<"const char * "<<p<<endl;} void f( char*p){cout<<"char * "<<p<<endl;} int main() {...
3
7491
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.