[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gccxml
Subject:    Re: [GCC-XML] virtual function
From:       Nindi Singh <nindi73 () yahoo ! co ! uk>
Date:       2008-02-02 15:05:41
Message-ID: 286034.81397.qm () web27910 ! mail ! ukl ! yahoo ! com
[Download RAW message or body]

Brad
Thanks, your absoluteley right BUT I didn't know that. I'll be sure to reference the \
standard before posting in the future.


N
PS It'd probably make a good interview question !


----- Original Message ----
> From: Brad King <brad.king@kitware.com>
> To: Nindi Singh <nindi73@yahoo.co.uk>
> Cc: gccxml@gccxml.org
> Sent: Saturday, 2 February, 2008 2:21:35 PM
> Subject: Re: [GCC-XML] virtual function
> 
> Nindi
> 
Singh
> 
wrote:
> > 
> 
class
> 
Base
> 
{
> > 
> 
 
> 
public:
> > 
> 
 
> 
 
> 
virtual
> 
void
> 
func()=0;
> > 
> 
};
> > 
> > 
> 
class
> 
Derived:public
> 
Base
> 
{
> > 
> 
 
> 
public:
> > 
> 
 
> 
 
> 
void
> 
func(){}
> > 
> 
};
> [snip]
> > 
> 
I
> 
am
> 
curious
> 
the
> 
method
> 
'func'
> 
in
> 
class
> 
Derived
> 
is
> 
described
> 
as
> 
virtual.
> 
Its
> 
not.
> 
If
> 
I
> 
am
> 
missing
> 
something,
> 
then
> 
how
> 
can
> 
I
> 
tell
> 
whether
> 
a
> 
function
> 
'may'
> 
be
> 
overloaded
> 
in
> 
a
> 
derived
> 
class
> 
or
> 
not.
> 
> Yes,
> 
it
> 
is
> 
declared
> 
virtual. 
> 
It
> 
does
> 
not
> 
matter
> 
whether
> 
the
> 
virtual 
> keyword
> 
is
> 
present. 
> 
If
> 
there
> 
is
> 
a
> 
function
> 
with
> 
the
> 
same
> 
signature
> 
in 
> the
> 
parent
> 
class
> 
that
> 
is
> 
declared
> 
virtual
> 
it
> 
implicitly
> 
makes
> 
your 
> function
> 
virtual. 
> 
This
> 
is
> 
a
> 
C++
> 
rule.
> 
> If
> 
instead
> 
you
> 
write
> 
> class
> 
Base
> 
{
> 
> 
 
> 
public:
> 
> 
 
> 
 
> 
virtual
> 
void
> 
func()=0;
> };
> class
> 
Derived:
> 
public
> 
Base
> 
{
> 
> 
 
> 
public:
> 
> 
 
> 
 
> 
void
> 
func(int)
> 
{}
> };
> 
> then
> 
Derived::func
> 
is
> 
not
> 
virtual
> 
because
> 
it
> 
does
> 
not
> 
match
> 
the 
> signature
> 
from
> 
Base::func. 
> 
Instead
> 
you
> 
will
> 
be
> 
left
> 
with
> 
an
> 
abstract 
> class
> 
because
> 
Base::func
> 
is
> 
pure-virtual
> 
so
> 
it
> 
must
> 
be
> 
defined
> 
in 
> Derived
> 
to
> 
make
> 
it
> 
a
> 
concrete
> 
type.
> 
> -Brad
> 
> 




      ___________________________________________________________
Support the World Aids Awareness campaign this month with Yahoo! For Good \
http://uk.promotions.yahoo.com/forgood/ \
_______________________________________________ gccxml mailing list
gccxml@gccxml.org
http://www.gccxml.org/mailman/listinfo/gccxml


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic