mv2112 wrote:XianForce wrote:Code: Select all
class object
{
protected:
int x;
public:
virtual int RetX()=0;
[b]virtual int RetY()=0;[/b]
};
Could that perhaps be why? If you can't access RetY, but you can access RetX, then that should solve it.
But if i had 100 different objects with multiple different functions and variables(and different variables types with the same name), i would have a base class with over a hundred different virtual functions which would be a pain to write.
Well why would they all have different functions?
I mean all objects will probably have mostly the same functions, they will just do something a little different.
Like for example, you could have a base object class like this:
Code: Select all
class Object
{
private:
Rectangle mRect;
char m_cType;
std::string mDescription;
public:
Object();
~Object();
virtual std::string Examine(); //Returns a string of text to output when this object is examined
virtual bool Use(); //Uses the object; Returns false if the object cannot be used
And from there, whatever other functions you need you make >.>
So an example object could be something like:
Code: Select all
class Potion : public Object
{
private:
//You'd probably have whatever your API's interpretation of an image is here, for rendering purposes
public:
Potion() { m_cType = TYPE_HEALING; mDescription = "A solution that restores 20 health points";}
~Potion(); //Free any resources the potion has here...
bool Use() {player.health += 20}
So, that's the gist of it... Obviously there would be some big questions regarding design when doing this, because the objects will probably need access to things such as the player... But that's another question, for another day I suppose.
I hope that helps...
Oh and if you want to use specific functions from the derived class, with a pointer to the base class, you can just cast it.