| 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
.
|
|
|
|
|

|
Related Articles |
|
|