🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.tools.misc
16 messages
16 total messages Started by Ranko Orlic Wed, 17 Apr 1996 17:00
[Q] Why doesn't this compile?
#5
Author: Ranko Orlic
Date: Wed, 17 Apr 1996 17:00
40 lines
1195 bytes
Using MSVC 4.0 compiler I get the following:

File test.cpp: ---------------------------------

class A {
public:
	class L {
	public:
		L() {}
		virtual void f() {
			int dummy = 0;
		}
	};
	A();
};

class B : public A {
	class L : public A::L {
	public:
		L() {}
		virtual void f() {
			A::L::f();
		}
	};
	B();
};

Compilation result: ----------------------------

test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
nonstatic member function
Error executing cl.exe.
test.obj - 1 error(s), 1 warning(s)

------------------------------------------------

Anybody knows what's wrong with it?
Thanks,

-- Ranko.
Re: [Q] Why doesn't this compile?
#6
Author: John Arisco
Date: Wed, 17 Apr 1996 18:24
53 lines
1738 bytes
Ranko Orlic <rorlic@eps.agfa.be> wrote:

>Using MSVC 4.0 compiler I get the following:

>File test.cpp: ---------------------------------

>class A {
>public:
>	class L {
>	public:
>		L() {}
>		virtual void f() {
>			int dummy = 0;
>		}
>	};
>	A();
>};

>class B : public A {
>	class L : public A::L {
>	public:
>		L() {}
>		virtual void f() {
>			A::L::f();
>		}
>	};
>	B();
>};

>Compilation result: ----------------------------

>test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
>nonstatic member function
>Error executing cl.exe.
>test.obj - 1 error(s), 1 warning(s)

>------------------------------------------------

>Anybody knows what's wrong with it?
>Thanks,

>-- Ranko.

You cannot call a non-static member function without specifying
an object.  The way you've written this, there is no way for B::L::f()
to set its "this" pointer.  Of course, if this is really what you want

to do, the declaration of B::L::f() is unnecessary, since B::L
 inherits the A::L::f() virtual method from its base class.

|  John Arisco   <arisco@tradewave.com>
|  TradeWave Corp, 3636 Executive Center Dr, #100, Austin, TX 78731
|  Voice: (512) 433-5313     Main: 433-5300     Fax: 433-5303
Re: [Q] Why doesn't this compile?
#7
Author: Pete Becker
Date: Wed, 17 Apr 1996 18:44
42 lines
1543 bytes
In article <317523C0.5042@eps.agfa.be>, rorlic@eps.agfa.be says...
>
>Using MSVC 4.0 compiler I get the following:
>
>File test.cpp: ---------------------------------
>
>class A {
>public:
>        class L {
>        public:
>                L() {}
>                virtual void f() {
>                        int dummy = 0;
>                }
>        };
>        A();
>};
>
>class B : public A {
>        class L : public A::L {
>        public:
>                L() {}
>                virtual void f() {
>                        A::L::f();
>                }
>        };
>        B();
>};
>
>Compilation result: ----------------------------
>
>test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
>nonstatic member function
>Error executing cl.exe.
>test.obj - 1 error(s), 1 warning(s)
>
>------------------------------------------------
>
>Anybody knows what's wrong with it?

There's nothing wrong with it. The problem is in your compiler.
	-- Pete
Re: [Q] Why doesn't this compile?
#8
Author: Chris Hill
Date: Wed, 17 Apr 1996 19:43
25 lines
1367 bytes
In article <317523C0.5042@eps.agfa.be>, rorlic@eps.agfa.be says...
>test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
>nonstatic member function
>Error executing cl.exe.
>test.obj - 1 error(s), 1 warning(s)
>
>------------------------------------------------
>
>Anybody knows what's wrong with it?
>Thanks,
>
>-- Ranko.

I think the error message is telling you exactly what is wrong.  You can't call 
A::L::f because it is not a static function.  A static function is shared 
between all instances of the class (it only has access to other static 
members), while nonstatic functions all have have access to  the instance 
specific data of the class. 

A::L::f requires that f is a static function.  Which A object do you expect the 
compiler to call f for?

-- 
Chris Hill
hillca@cs.purdue.edu
Re: [Q] Why doesn't this compile?
#12
Author: Rob Woerner
Date: Wed, 17 Apr 1996 22:24
14 lines
1059 bytes
In article <4l3e5l$e1t@druid.borland.com> pete@borland.com (Pete Becker) writes:
>In article <317523C0.5042@eps.agfa.be>, rorlic@eps.agfa.be says...
>>
[snip]
>>
>>Anybody knows what's wrong with it?
>
>There's nothing wrong with it. The problem is in your compiler.
>	-- Pete
>

I agree. However, you can work around it by declaring L outside of A, and
changing the name of B::L to (say) B::W. The way it is has a hidden 'L', inherited from A, but masked by B::L.
I think it is confused by the 2 consecutive '::' operators.
Re: [Q] Why doesn't this compile?
#9
Author: Jason D. Smith
Date: Wed, 17 Apr 1996 23:20
24 lines
1176 bytes
In article <317523C0.5042@eps.agfa.be>, Ranko Orlic <rorlic@eps.agfa.be> wrote:
[ ... ]
= Compilation result: ----------------------------
= 
= test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
= nonstatic member function
= Error executing cl.exe.
= test.obj - 1 error(s), 1 warning(s)
= 
= ------------------------------------------------
= 
= Anybody knows what's wrong with it?

The compiler being used to compile it.

Your welcome.

Jason.

Jason.

------------------------------------------------------------------------
Jason D. Smith |       I'm not young enough to know everything.        |
smithj@ngc.com |                                                       |
Re: [Q] Why doesn't this compile?
#10
Author: Ranko Orlic
Date: Thu, 18 Apr 1996 07:10
21 lines
1584 bytes
> You cannot call a non-static member function without specifying
> an object.  The way you've written this, there is no way for B::L::f()
> to set its "this" pointer.  Of course, if this is really what you want
> to do, the declaration of B::L::f() is unnecessary, since B::L
> inherits the A::L::f() virtual method from its base class.
> 
> |  John Arisco   <arisco@tradewave.com>

Dear John, (where have I heard this song before, Status Quo perhaps?)

a) It was just an example, in real life I'd called the base class implementation A::L::f() and done something 
useful in addition.
b) B::L::f() IS a regular member function, not a static one, so the compiler does have a this pointer! The 
problem is the compiler which thinks is a static member function. I've tried it on other compilers (on both Mac 
and Sun), and they have no trouble with it.

Regards,

-- Ranko.

PS. thanks anyhow for your response
Re: [Q] Why doesn't this compile?
#11
Author: Ranko Orlic
Date: Thu, 18 Apr 1996 07:17
16 lines
1129 bytes
> ... You can't call A::L::f because it is not a static function ...
> ... A::L::f requires that f is a static function ...
> 
> --
> Chris Hill
> hillca@cs.purdue.edu

Hi Chris,

According to me you did not understand the error message completely.
The compiler incorrectly thinks that B::L::f is a static member function.
The code IS perfectly legal. The compiler simply does not work properly.

Thanks for your response, I really appreciate it.

-- Ranko.
Re: [Q] Why doesn't this compile?
#13
Author: Rob Stewart
Date: Thu, 18 Apr 1996 14:19
71 lines
2932 bytes
John Arisco wrote:
> 
> Ranko Orlic <rorlic@eps.agfa.be> wrote:
> 
> >Using MSVC 4.0 compiler I get the following:
> 
> >File test.cpp: ---------------------------------
> 
> >class A {
> >public:
> >       class L {
> >       public:
> >               L() {}
> >               virtual void f() {
> >                       int dummy = 0;
> >               }
> >       };
> >       A();
> >};
> 
> >class B : public A {
> >       class L : public A::L {
> >       public:
> >               L() {}
> >               virtual void f() {
> >                       A::L::f();
> >               }
> >       };
> >       B();
> >};
> 
> >Compilation result: ----------------------------
> 
> >test.cpp(18) : error C2352: 'A::L::f' : illegal call of
> >nonstatic member function
> >Error executing cl.exe.
> >test.obj - 1 error(s), 1 warning(s)
> [snip]
> You cannot call a non-static member function without specifying
> an object.  The way you've written this, there is no way for B::L::f()
> to set its "this" pointer.  Of course, if this is really what you want
> 
> to do, the declaration of B::L::f() is unnecessary, since B::L
>  inherits the A::L::f() virtual method from its base class.
> 

That's nonsensical.  We're talking class declarations here.  
B::L::f is a non-static member function of B::L, so it has a 
this pointer.

I moved A::L out of A, making it just L, and I changed B::L to 
B::BL, and it compiled fine.  Then I thought, could it be the 
names were causing a problem?  So, I moved L back into A, but 
left BL as is.  I got the original error.  I also moved BL out 
of B, leaving L nested in A.  I got the original error.  
Finally, I made both functions f non-inline.  I got the 
original error.  Clearly, the problem has to do with deriving 
from a nested class.

I don't think that should be a problem, but clearly VC doesn't 
handle it.  So, I decided to try another compiler.  Compiling 
under Silicon Graphics' C++ (NCC) v4.0.  This isn't enough to 
justify my interpretation that it should work, but it is 
comforting.

BTW, I did a cursory examination of the Jan DWP and found 
nothing to suggest that it shouldn't work.

-- 
Robert Stewart		| My opinions are usually my own.
Datalytics, Inc.	| stew@datalytics.com
Re: [Q] Why doesn't this compile?
#19
Author: Bryan McGuire
Date: Thu, 18 Apr 1996 14:46
13 lines
1116 bytes
woerner@netcom.com (Rob Woerner) wrote:

>I agree. However, you can work around it by declaring L outside of A, and
>changing the name of B::L to (say) B::W. The way it is has a hidden 'L', inherited from A, but masked by B::L.
>I think it is confused by the 2 consecutive '::' operators.

1. I disagree,  B::L is not the same scope as A::L. Only static member
   functions can be called out of scope.

2. B::L::f() would use A::L::f() anyway because of how B was inherited
from A.

3. Has anyone noticed that B's constructor is private?
Re: [Q] Why doesn't this compile?
#14
Author: Pete Becker
Date: Thu, 18 Apr 1996 16:19
56 lines
2241 bytes
In article <4l3cpv$l74@helium.einet.net>, arisco@tradewave.com says...
>
>Ranko Orlic <rorlic@eps.agfa.be> wrote:
>
>>Using MSVC 4.0 compiler I get the following:
>
>>File test.cpp: ---------------------------------
>
>>class A {
>>public:
>>       class L {
>>       public:
>>               L() {}
>>               virtual void f() {
>>                       int dummy = 0;
>>               }
>>       };
>>       A();
>>};
>
>>class B : public A {
>>       class L : public A::L {
>>       public:
>>               L() {}
>>               virtual void f() {
>>                       A::L::f();
>>               }
>>       };
>>       B();
>>};
>
>>Compilation result: ----------------------------
>
>>test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
>>nonstatic member function
>>Error executing cl.exe.
>>test.obj - 1 error(s), 1 warning(s)
>
>>------------------------------------------------
>
>>Anybody knows what's wrong with it?
>>Thanks,
>
>>-- Ranko.
>
>You cannot call a non-static member function without specifying
>an object.  The way you've written this, there is no way for B::L::f()
>to set its "this" pointer.  Of course, if this is really what you want
>
>to do, the declaration of B::L::f() is unnecessary, since B::L
> inherits the A::L::f() virtual method from its base class.

Huh? The call is perfectly legal, and the scope qualifier is necessary. The 
nesting makes things look more complicated, but this is nothimg more than a 
virtual function calling the corresponding function in the base class. The name 
of that base class is A::L, which is why things look a little nasty.
Re: [Q] Why doesn't this compile?
#15
Author: Pete Becker
Date: Thu, 18 Apr 1996 17:40
29 lines
1646 bytes
In article <4l3hlj$6qt@mozo.cc.purdue.edu>, hillca@cs.purdue.edu says...
>
>In article <317523C0.5042@eps.agfa.be>, rorlic@eps.agfa.be says...
>>test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
>>nonstatic member function
>>Error executing cl.exe.
>>test.obj - 1 error(s), 1 warning(s)
>>
>>------------------------------------------------
>>
>>Anybody knows what's wrong with it?
>>Thanks,
>>
>>-- Ranko.
>
>I think the error message is telling you exactly what is wrong.  You can't 
call 
>A::L::f because it is not a static function.  A static function is shared 
>between all instances of the class (it only has access to other static 
>members), while nonstatic functions all have have access to  the instance 
>specific data of the class. 
>
>A::L::f requires that f is a static function.  Which A object do you expect 
the 
>compiler to call f for?

There is no A object involved. B::L is derived from A::L, and the call 
A::L::f() is calling the f() that's defined in A::L. This call is legal. It's 
the compiler that's wrong.
Re: [Q] Why doesn't this compile?
#16
Author: John Arisco
Date: Thu, 18 Apr 1996 18:15
48 lines
2554 bytes
I   wrote:
>> You cannot call a non-static member function without specifying
>> an object.  The way you've written this, there is no way for B::L::f()
>> to set its "this" pointer.

Rob Stewart <stew@datalytics.com> wrote:
> That's nonsensical.  We're talking class declarations here.  
> B::L::f is a non-static member function of B::L, so it has a
> this pointer.

Although Rob is correct, what I meant to say was that there is
no way to set the "this" pointer for B::L::f()'s call to  A::L::f().
(In other words, when I said "its", I meant "A::L::f()'s", not "its
own".)  Unfortunately, I was still wrong.

Chris Hill <hillca@cs.purdue.edu> wrote:
> A::L::f requires that f is a static function.  Which A object do
> you expect the compiler to call f for?

This is what I meant in my first post.  However, it is wrong,
because A::L is a base class of B::L, and the syntax for a
method in a derived class to call a function in its base class
is  baseclassname::f().  When viewed in light of this, the call
to A::L::f() definitely has a valid "this" pointer.

Ranko Orlic <rorlic@eps.agfa.be> responded to Chris:
> According to me you did not understand the error message
> completely. The compiler incorrectly thinks that B::L::f is a
> static member function.

I don't think so.  I think the compiler made the same error that
I made.  It didn't recognize that B::L::f() was calling a function
in it's own base class, so it assumed that A::L::f() was a static
function call, and it barfed because A::L::f() was not declared
static.

Ranko goes on to say:
> The code IS perfectly legal. The compiler simply does not
> work properly.

Yes, I now agree with Rob and Ranko that this is a compiler
bug and not a coding error. 

Sometimes you get the bear, sometimes the bear gets you.

|  John Arisco   <arisco@tradewave.com>
|  TradeWave Corp, 3636 Executive Center Dr, #100, Austin, TX 78731
|  Voice: (512) 433-5313     Main: 433-5300     Fax: 433-5303
Re: [Q] Why doesn't this compile?
#17
Author: Andrew Tucker
Date: Thu, 18 Apr 1996 18:22
13 lines
1141 bytes
Chris Hill (hillca@cs.purdue.edu) wrote:
: In article <317523C0.5042@eps.agfa.be>, rorlic@eps.agfa.be says...
: A::L::f requires that f is a static function.  Which A object do you expect t: he compiler to call f for?

The current one that B is derived from.  He is just calling a base class 
function from B::L's overloaded f. 

The syntax/logic is correct, the compiler is broken.

--
--
/*  Andrew  */         
Email: ast@halcyon.com 
Re: [Q] Why doesn't this compile?
#18
Author: Brian Maiorella
Date: Fri, 19 Apr 1996 05:22
24 lines
1487 bytes
On Wed, 17 Apr 1996 19:00:48 +0200, Ranko Orlic <rorlic@eps.agfa.be>
wrote:

>test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
>nonstatic member function
>Error executing cl.exe.
>test.obj - 1 error(s), 1 warning(s)
>

Simple.  Compiler bug.  We noticed problems with nested class
declarations in VC1.  When reported to people at Microsoft we couldn't
find anyone who could understand the problem.  

Invariably, after waiting on hold for a half hour then describing the
problem to 3 different people each time a little faster and a little
louder, conversations with support representatives would end with "So
if it works when you don't nest your classes, maybe you shouldn't be
nesting your classes.."

Just makes you spew out "Have a nice day" as you slam the receiver and
start shouting obscenities as a client walks by who has just
unknowingly spent a forture for no good reason.

-brian
Re: [Q] Why doesn't this compile?
#20
Author: Bryan McGuire
Date: Fri, 19 Apr 1996 11:44
10 lines
874 bytes
rmcguir@hubcap.clemson.edu (Bryan McGuire) wrote:


>1. I disagree,  B::L is not the same scope as A::L. Only static member
>   functions can be called out of scope.

>2. B::L::f() would use A::L::f() anyway because of how B was inherited
>from A.

Oops, never mind!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads