Sign in to follow this  
ratha

Doubt in C++ Inheritance

Recommended Posts

Hi!
I've to maintain somebody's code. There is a derivation like the following:

[code]
class TSession: public IServer, public m_object::TObject
[/code]

What's the meaning of:

[code] public m_object::TObject[/code]

What's the difference between
[code]
class TSession: public IServer
[/code]

and

[code]
class TSession:public m_object::TObject
[/code]

Share this post


Link to post
Share on other sites
It's C++ multiple inheritance (google the last three words for more information)

But from the class prefix, it's that,
1, TSession inherits from TObject
2, TSession implements the interface IServer

It's better to write interface after parent class,
[code]class TSession: public m_object::TObject, public IServer [/code]

Share this post


Link to post
Share on other sites
[quote name='wqking' timestamp='1307527455' post='4820861']
It's C++ multiple inheritance (google the last three words for more information)

But from the class prefix, it's that,
1, TSession inherits from TObject
2, TSession implements the interface IServer

It's better to write interface after parent class,
[code]class TSession: public m_object::TObject, public IServer [/code]
[/quote]

It should be noted that C++ doesn't have such a thing as an "interface", this is only emulated by an abstract class that, by common convention, that has a 0 implementation for all of its functions (all of which are virtual) and no data members.

Share this post


Link to post
Share on other sites
[quote name='wqking' timestamp='1307527455' post='4820861']
It's C++ multiple inheritance (google the last three words for more information)

But from the class prefix, it's that,
1, TSession inherits from TObject
2, TSession implements the interface IServer

It's better to write interface after parent class,
[code]class TSession: public m_object::TObject, public IServer [/code]
[/quote]

Sorry. I actually asked a different question than what I thought to ask. I know Multiple inheritance. What's the difference between

[code]class TSession: public m_object::TObject[/code]

and

[code]class TSession: public TObject[/code]

Why "m_object::TObject" is used instead of "TObject"? I saw and practiced like the later(mear "TObject").
That's why I asked the significance of "m_object::TObject"?

Share this post


Link to post
Share on other sites
m_object::TObject is a kind of very weird style according to the name m_object.
You should check the declaration of m_object.
It should be a class, structure, or,..., namespace.

m_object::TObject means a type TObject in a scope named TObject (class, namespace, whatever).

[code]
class m_object {
public:
class TObject {
// blah blah
};
};
[/code]

Edited: Does m_object mean meta object in your code style? :rolleyes:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this