16
General / Inheriting from structs?
« on: August 25, 2013, 07:59:21 pm »
Hello i just got some problems and I got confused.
I have POD that handles typical attributes for a game entity.So I presented it this way:
I recreated this snippet using this code and I can't figure out how am I suppose to inherit just variables on deriving structs? Is this even possible? I have a container for attribute and I don't want creating a separate containers for two. Well I could save myself some troubles if I could write this as a full pledge class but I just want handler that handle values distinct to tiles and asset so I just used POD.
How can I fix this?
Thanks for your help!
I have POD that handles typical attributes for a game entity.So I presented it this way:
#include<iostream>
#include<string>
using namespace std;
struct Attribute
{
string directory;
string name;
};
struct TileAttribute : public Attribute
{
int cost;
};
struct AssetAttribute : public Attribute
{
int cost;
};
int main()
{
Attribute * attribute = new TileAttribute;
attribute->cost; // no such thing as cost in TileAttribute; error
// WHAT's the big deal if I use "."? I am asking why can't I access cost? I think I am missing something here
// Thanks for the correction anyway.
return 0;
}
#include<string>
using namespace std;
struct Attribute
{
string directory;
string name;
};
struct TileAttribute : public Attribute
{
int cost;
};
struct AssetAttribute : public Attribute
{
int cost;
};
int main()
{
Attribute * attribute = new TileAttribute;
attribute->cost; // no such thing as cost in TileAttribute; error
// WHAT's the big deal if I use "."? I am asking why can't I access cost? I think I am missing something here
// Thanks for the correction anyway.
return 0;
}
I recreated this snippet using this code and I can't figure out how am I suppose to inherit just variables on deriving structs? Is this even possible? I have a container for attribute and I don't want creating a separate containers for two. Well I could save myself some troubles if I could write this as a full pledge class but I just want handler that handle values distinct to tiles and asset so I just used POD.
How can I fix this?
Thanks for your help!