Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

Inheritance question

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a base class Object with name, id, a dispose method etc. But when I Inherit it I can't see any of those methods and it won't let me compile saying method doesn't exist. I am using c++ vs2003 and directx. For example my Input class doesn't see the object methods. This is just some psuedocode. Is there any reason why something wouldn't be inherited?

class Object
{
public:
 getName();
}

class Input : public Object
{
 //Whatever in here
}

Input i;

i.getName(); //Error


Share this post


Link to post
Share on other sites
Advertisement
I didn't want to post all my code because that would be alot to look through. It doesn't come up in Intellisense. I think it would come up there. The inheritance itself doesn't give a compiler error. All I wanted to know is there any reason why something wouldn't be inherited? Not just in my code but any code?

Share this post


Link to post
Share on other sites
It could be declared private in the base class, or you could have not used public inheritence in the derived class.

Share this post


Link to post
Share on other sites
Yah I checked that but all the methods I have in the base class are public, and in the child class i have it publicly inherit.

Share this post


Link to post
Share on other sites
I think i have gotten closer to the error. I have namespaces, so will that cause an inheritance error.

Example


namespace BaseClass
{
class Object
{
public:
getName();
}
}

namespace InputClass
{
class Input : public BaseClass::Object
{
//Whatever in here
}
}

Input i;

i.getName(); //Error





EDIT:: I can use the methods from the base class if it's in the same namespace, but if I inherit in a different namespace i can't. Is there something wrong in my code, or do I need to reference the namespace somehow I thought I was with the class Input : public BaseClass::Object.

Share this post


Link to post
Share on other sites
Im out of ideas then, how can I see the methods if they are in the same namespace but if its not I can't see the methods. I'm getting ready to go to a different language.

Share this post


Link to post
Share on other sites
Zip your code or post your class design. You only need the 2 classes.

The base and the inherited. Then show us the implementation.

Its ok to have a lot of code posted.

Share this post


Link to post
Share on other sites
this code works fine, and they are in different namespaces

#include <iostream>

namespace One{
class Test{
public:
int getOne(){
return 550;
}
};

}


namespace Two{

class TestTwo : public One::Test{

};

}



int main(){
Two::TestTwo obj;
std::cout << obj.getOne() << std::endl;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!