Topic: ANCESTOR keyword wanted!
Author: mansionj@lonnds.ml.com (James Mansion LADS LDN X4923)
Date: 1995/06/15 Raw View
This would appear to be fixed in VC 2.1.
I don't know about the 16 bit compiler - I didn't install it.
James
In article <BrianS-1106951750420001@slip-1-38.ots.utexas.edu>, BrianS@pbcomputing.com (Brian Stern) writes:
>In article <DA13wF.M3L@actrix.gen.nz>, hugp@actrix.gen.nz (Peter Hug) wrote:
>
>< Quite some time ago I posted a similar message to comp.std.c++ and got
>< a few responses to my message saying that I could use a typedef within
>< the class scope to describe my ancestor as in this example:
><
>< 1: class CAncestor {
>< 2: protected:
>< 3: int foo () { return 10; };
>< 4: };
>< 5:
>< 6: class CDescendant : public CAncestor {
>< 7: protected:
>< 8: typedef CAncestor ancestor;
>< 9: int foo () { return ancestor::foo() * 2; }; // <-- MSVC error
>< 10:};
><
>< But I am getting these two errors when compiling with MSVC 1.5:
><
>< c:\test\test.cpp(9) : error C2248: 'foo' : cannot access protected
>< member declared in class 'CAncestor'
>< c:\test\test.cpp(9) : error C2352: 'CAncestor::foo' : illegal call of
>< nonstatic member function
><
>< Am I missing something?
><
>< Cheers
>
>Just out of curiosity I compiled this code with CodeWarrior Mac and it
>compiled with no errors. Is there more to this code that you haven't
>shown us? The error messages suggest that the compiler thinks that
>CDescendant::foo is declared static.
>
>FYI, what you are doing here is the same as the inherited keyword. It's
>use is mentioned in the C++ programming language and its history in D&E.
>It is directly supported by compilers on the Mac, but not any others that
>I'm aware of.
>
>____________________________________________________________________
>Brian Stern {:-{)} BrianS@pbcomputing.com
>Toolbox commando and Menu bard. Will FlushCache for Cash
Author: maccullt@cognos.com (W. Todd MacCulloch)
Date: 1995/06/16 Raw View
In article <DA7y4y.CE5@tigadmin.ml.com>, mansionj@lonnds.ml.com says...
>>FYI, what you are doing here is the same as the inherited keyword. It's
>>use is mentioned in the C++ programming language and its history in D&E.
>>It is directly supported by compilers on the Mac, but not any others that
>>I'm aware of.
Bzzt. There's no inherited "keyword". As mentioned in D&E they were going to add
one when it was pointed out that class scoped typedefs could accomplish the same
thing with no addition to the language.
Brian is in the same position as I am in that our compiler (MSVC 1.5x) doesn't
support member function invocation through typedef'd synonyms.
CodeWarrior probably supports an inherited keyword which is a non-standard extention
in ThinkC as well.
--
W. Todd MacCulloch | Cognos Inc.
Voice: (613) 738-1338 ext 3202 | 3755 Riverside Drive
fax: (613) 247-1176 | Ottawa ON CANADA
Internet: maccullt@cognos.com | K1G 4K9
Author: Raoul De Kezel <raoul.de.kezel@infoboard.be>
Date: 1995/06/15 Raw View
hugp@actrix.gen.nz (Peter Hug) wrote:
>1: class CAncestor {
>2: protected:
>3: int foo () { return 10; };
>4: };
>5:
>6: class CDescendant : public CAncestor {
>7: protected:
>8: typedef CAncestor ancestor;
>9: int foo () { return ancestor::foo() * 2; }; // <-- MSVC error
>10:};
Works like a charm with BC4.5.
But we use *private* visibility for ancestor. This saves us when we
inadvertently forget to typedef ancestor in a new class.
Best Regards
--- Raoul De Kezel
Author: hugp@actrix.gen.nz (Peter Hug)
Date: 1995/06/11 Raw View
Quite some time ago I posted a similar message to comp.std.c++ and got
a few responses to my message saying that I could use a typedef within
the class scope to describe my ancestor as in this example:
1: class CAncestor {
2: protected:
3: int foo () { return 10; };
4: };
5:
6: class CDescendant : public CAncestor {
7: protected:
8: typedef CAncestor ancestor;
9: int foo () { return ancestor::foo() * 2; }; // <-- MSVC error
10:};
But I am getting these two errors when compiling with MSVC 1.5:
c:\test\test.cpp(9) : error C2248: 'foo' : cannot access protected
member declared in class 'CAncestor'
c:\test\test.cpp(9) : error C2352: 'CAncestor::foo' : illegal call of
nonstatic member function
Am I missing something?
Cheers
Author: BrianS@pbcomputing.com (Brian Stern)
Date: 1995/06/11 Raw View
In article <DA13wF.M3L@actrix.gen.nz>, hugp@actrix.gen.nz (Peter Hug) wrote:
< Quite some time ago I posted a similar message to comp.std.c++ and got
< a few responses to my message saying that I could use a typedef within
< the class scope to describe my ancestor as in this example:
<
< 1: class CAncestor {
< 2: protected:
< 3: int foo () { return 10; };
< 4: };
< 5:
< 6: class CDescendant : public CAncestor {
< 7: protected:
< 8: typedef CAncestor ancestor;
< 9: int foo () { return ancestor::foo() * 2; }; // <-- MSVC error
< 10:};
<
< But I am getting these two errors when compiling with MSVC 1.5:
<
< c:\test\test.cpp(9) : error C2248: 'foo' : cannot access protected
< member declared in class 'CAncestor'
< c:\test\test.cpp(9) : error C2352: 'CAncestor::foo' : illegal call of
< nonstatic member function
<
< Am I missing something?
<
< Cheers
Just out of curiosity I compiled this code with CodeWarrior Mac and it
compiled with no errors. Is there more to this code that you haven't
shown us? The error messages suggest that the compiler thinks that
CDescendant::foo is declared static.
FYI, what you are doing here is the same as the inherited keyword. It's
use is mentioned in the C++ programming language and its history in D&E.
It is directly supported by compilers on the Mac, but not any others that
I'm aware of.
____________________________________________________________________
Brian Stern {:-{)} BrianS@pbcomputing.com
Toolbox commando and Menu bard. Will FlushCache for Cash
Author: chris@double.actrix.gen.nz (Chris Double)
Date: 1995/06/12 Raw View
>Quite some time ago I posted a similar message to comp.std.c++ and got
>a few responses to my message saying that I could use a typedef within
>the class scope to describe my ancestor as in this example:
>
>1: class CAncestor {
>2: protected:
>3: int foo () { return 10; };
>4: };
>5:
>6: class CDescendant : public CAncestor {
>7: protected:
>8: typedef CAncestor ancestor;
>9: int foo () { return ancestor::foo() * 2; }; // <-- MSVC error
>10:};
>
>But I am getting these two errors when compiling with MSVC 1.5:
>
>c:\test\test.cpp(9) : error C2248: 'foo' : cannot access protected
> member declared in class 'CAncestor'
>c:\test\test.cpp(9) : error C2352: 'CAncestor::foo' : illegal call of
> nonstatic member function
>
>Am I missing something?
Yes. You missed a reply by W. Todd MacCulloch (maccullt@cognos.com) that gave
you an answer to your query. I've copied part of his reply below.
Cheers
Chris.
Message from W. Todd MacCulloch (maccullt@cognos.com):
>>>> But I am getting these two errors:
>>>>
>>>> c:\test\test.cpp(9) : error C2248: 'foo' : cannot access private
>>>> member declared in class 'CAncestor'
>>>> c:\test\test.cpp(9) : error C2352: 'CAncestor::foo' : illegal call of
>>>> nonstatic member function
>>>>
>
>Part of your problem is a MSVC 1.5x bug, it doesn't allow member function
>invocation through typedef'd synonyms. That is, the extremely useful
>idiom of typedefing inherited (or in your case, ancestor) to be you baser
>class won't work (this strategy is outlined in Bjarne's Design &
>Evoloution among other places).
This might or might not be fixed MSVC 2+, I haven't checked.
Author: herbs@interlog.com (Herb Sutter)
Date: 1995/06/12 Raw View
In article <DA13wF.M3L@actrix.gen.nz>, hugp@actrix.gen.nz (Peter Hug) wrote:
>Quite some time ago I posted a similar message to comp.std.c++ and got
>a few responses to my message saying that I could use a typedef within
>the class scope to describe my ancestor as in this example:
>
>1: class CAncestor {
>2: protected:
>3: int foo () { return 10; };
>4: };
>5:
>6: class CDescendant : public CAncestor {
>7: protected:
>8: typedef CAncestor ancestor;
>9: int foo () { return ancestor::foo() * 2; }; // <-- MSVC error
>10:};
>
>But I am getting these two errors when compiling with MSVC 1.5:
>
>c:\test\test.cpp(9) : error C2248: 'foo' : cannot access protected
> member declared in class 'CAncestor'
>c:\test\test.cpp(9) : error C2352: 'CAncestor::foo' : illegal call of
> nonstatic member function
>
>Am I missing something?
Well, a modern compiler wouldn't hurt. :-)
Just kidding; MSVC isn't all that bad any more these days... but your code
compiles fine under Borland 4.5. BTW, I know it's just an example, but
you're also overriding a nonvirtual function.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herb Sutter 2228 Urwin, Ste 102 voice (416) 618-0184
Connected Object Solutions Oakville ON Canada L6L 2T2 fax (905) 847-6019
Author: glascock@esd.dl.nec.com (Trent Glascock)
Date: 1995/06/13 Raw View
In article <BrianS-1106951750420001@slip-1-38.ots.utexas.edu>, BrianS@pbcomputing.com says...
|
|In article <DA13wF.M3L@actrix.gen.nz>, hugp@actrix.gen.nz (Peter Hug) wrote:
|
|< Quite some time ago I posted a similar message to comp.std.c++ and got
|< a few responses to my message saying that I could use a typedef within
|< the class scope to describe my ancestor as in this example:
|<
|< 1: class CAncestor {
|< 2: protected:
|< 3: int foo () { return 10; };
|< 4: };
|< 5:
|< 6: class CDescendant : public CAncestor {
|< 7: protected:
|< 8: typedef CAncestor ancestor;
|< 9: int foo () { return ancestor::foo() * 2; }; // <-- MSVC error
|< 10:};
|<
|< But I am getting these two errors when compiling with MSVC 1.5:
|<
|< c:\test\test.cpp(9) : error C2248: 'foo' : cannot access protected
|< member declared in class 'CAncestor'
|< c:\test\test.cpp(9) : error C2352: 'CAncestor::foo' : illegal call of
|< nonstatic member function
|<
|< Am I missing something?
|<
|< Cheers
|
|Just out of curiosity I compiled this code with CodeWarrior Mac and it
|compiled with no errors. Is there more to this code that you haven't
|shown us?
No, there are many bugs in MSVC 1.5. This is one. Just another reason
to move to Borland.
--
Trent Glascock
glascock@esd.dl.nec.com
Speaking only for myself