473,657 Members | 2,392 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::f oo()

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 1203
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::f oo()

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
2079
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
3958
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 will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
19
3563
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 one web presentation tier (Foo.WebFiles). The data tier shall only be accessible thru the business tier so I do NOT want a reference to the data tier in the presentation tier. In the business tier I have a class with the name CategoryItem that...
35
2160
by: Maxim Yegorushkin | last post by:
The following code: #include <iostream> class base { private: virtual ~base() { std::cout << "virtual ~base()\n";
9
3134
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 form, __gc class CManagedClass { __nogc CNativeClass {
0
2555
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 hyperlinks generated for the expand/collapse buttons includes javascript code that will execute in the frame specified in the Base Target rather than the current document. To remedy this, TreeView should render a target="_self" attribute for each...
14
2322
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"); if(!id) id=stdin; I have read about streams but I haven't found how to do it, I suppose
7
4258
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 output is 1970.1.1 7:56:40, when ut is 0, the output is 1970.1.1 8:00:00, when ut is 86400, the output is 1970.1.2 8:00:00. While output will be 1970 1.2 7:56:40 in VC8. Please note that I am aware that time_t is 64bit in VC2005 and using...
4
1423
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() { f("hello");
3
7505
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 on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a datetimepicker ("Value") for it's "DateTime" property. The DateTimePicker.Visible value is set to...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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 we have to send another system
2
1969
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.