C++ newbie: overriding inherited function

V

victorcionca

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::eek:nGotRR(....)
.....
}

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

mlimber

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::eek:nGotRR(....)
....

}

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::eek:nGotRR() { /* override */ }
}

Cheers! --M
 
V

victorcionca

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top