Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What does the standard say about this

Reply
Thread Tools

What does the standard say about this

 
 
Xenos
Guest
Posts: n/a
 
      07-10-2004
I just spend about an hour tracking down a link error with GCC. I had
defined a virtual member function, but never referenced it. With this
declaration, the linker would complain that the virtual table for the class
was missing. I know that it is acceptable by the standard to declare a
non-virtual member but not define it, if it is never accessed. Is the same
true for virtual members?

Thanks,

DrX


 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      07-10-2004
Xenos wrote in news:9DTHc.28395$(E-Mail Removed) in
comp.lang.c++:

> I just spend about an hour tracking down a link error with GCC. I had
> defined a virtual member function, but never referenced it. With this
> declaration, the linker would complain that the virtual table for the
> class was missing. I know that it is acceptable by the standard to
> declare a non-virtual member but not define it, if it is never
> accessed. Is the same true for virtual members?
>


No, but you can declare the member pure-virtual, in which case
(as long as it isn't the destructor) you don't need a defenition.

However it makes the class *abstract*, i.e. you may not create
instances of it (even if you do provide a defenition).

struct X
{
virtual int f() = 0; /* = 0 means: pure */
};

struct Y : X
{
virtual int f();
};

int Y::f()
{
return 0;
}

int main()
{
Y y;
return y.f();
}

Rob.
--
http://www.victim-prime.dsl.pipex.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You Say “Fragmentation”, I Say “Differentiation” Lawrence D'Oliveiro NZ Computing 2 10-06-2010 04:44 AM
You say SIM, I say SEM Anon Computer Security 1 03-18-2006 01:49 PM
Re: What does the standard say? Sten Westerback C Programming 3 04-06-2004 01:24 AM
Integer value wraparound -- what does the C++ standard say? Dave Rahardja C++ 5 07-18-2003 06:46 PM
what does the standard say about parameter passing? Tobias Oed C Programming 11 06-30-2003 02:05 PM



Advertisments