Article View: comp.os.ms-windows.programmer.tools.misc
Article #13Re: [Q] Why doesn't this compile?
From: Rob Stewart
Date: Thu, 18 Apr 1996 14:19
Date: Thu, 18 Apr 1996 14:19
71 lines
2932 bytes
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
Technical Details
Message-ID:
<31764F78.4259@datalytics.com>Path:
arc1-ca.pugleaf.net!news.sprintlink.net!datalytics!usenetReferences:
<317523C0.5042@eps.agfa.be> <4l3cpv$l74@helium.einet.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.sprintlink.net!datalytics!usenet From: Rob Stewart <stew@datalytics.com> Newsgroups: comp.os.ms-windows.programmer.tools.misc,comp.os.ms-windows.programmer.win32,comp.os.ms-windows.programmer.misc,comp.lang.c++ Subject: Re: [Q] Why doesn't this compile? Date: Thu, 18 Apr 1996 10:19:36 -0400 Organization: Datalytics, Inc Message-ID: <31764F78.4259@datalytics.com> References: <317523C0.5042@eps.agfa.be> <4l3cpv$l74@helium.einet.net> NNTP-Posting-Host: 204.62.224.71 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 2.0 (WinNT; I)