C++ newbie: overriding inherited function



 DEVELOP > c-Plus-Plus > C++ newbie: overriding inherited function

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 21 Mar 2007 07:24:53 AM
Object: C++ newbie: overriding inherited function
Hi
I am trying to write a class using the ccRTP library. This class
inherits from a RTPSession class and overrides several methods, one of
them being onGotRR.
I would like to separate the class definition from the implementation
(h file and cpp file), but I cannot get it right.
I declare the class
namespace rtptest{
class Receiver: RTPSession {
....
void onGotRR(..);
};
}
and
when I implement:
namespace rtptest {
....
void onGotRR(...); ->error: method doesn't match with the one defined
in the upper class
....
}
If I implement it
namespace rtptest {
.....
void ccrtpnamespace::QueueRTCPManager::onGotRR(....)
.....
}
it fails because I woul need to use an object to call the method.
However, if I don't split the class -> use inline methods,
namespace rtptest{
class Receiver: RTPSession{
.....
void onGotRR(...){
......
}
......
};
}
everything works fine, no errors. Why is that? And I really would like
to have them separated.
.

User: "mlimber"

Title: Re: C++ newbie: overriding inherited function 21 Mar 2007 07:35:47 AM
On Mar 21, 8:24 am,
wrote:

Hi

I am trying to write a class using the ccRTP library. This class
inherits from a RTPSession class and overrides several methods, one of
them being onGotRR.

I would like to separate the class definition from the implementation
(h file and cpp file), but I cannot get it right.

I declare the class

namespace rtptest{
class Receiver: RTPSession {
...
void onGotRR(..);

};
}

and
when I implement:
namespace rtptest {
...
void onGotRR(...); ->error: method doesn't match with the one defined
in the upper class
...

}

If I implement it
namespace rtptest {
....
void ccrtpnamespace::QueueRTCPManager::onGotRR(....)
....

}

it fails because I woul need to use an object to call the method.

However, if I don't split the class -> use inline methods,

namespace rtptest{
class Receiver: RTPSession{
....
void onGotRR(...){
.....

}
.....
};
}

everything works fine, no errors. Why is that? And I really would like
to have them separated.

The ellipses and syntax errors make it hard to figure what you're
doing wrong. See this guideline on posting code that doesn't work:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8
In essence is should be something like this:
namespace rtptest
{
class RTPSession
{
public: // Presumably
virtual void onGotRR() { /*default behavior*/ }
};
class Receiver
: public RTPSession // Note public
{
public: // Presumably
virtual void onGotRR(); // virtual is optional here
};
}
namespace rtptest
{
void Receiver::onGotRR() { /* override */ }
}
Cheers! --M
.
User: ""

Title: Re: C++ newbie: overriding inherited function 21 Mar 2007 07:44:32 AM
Thank you for the quick reply! It worked. I was just starting to read
about virtual methods...
Sorry about the sloppy code posting, I will try to do better next
time.
Victor
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER