A
Alex
Hello. I want to manage a class hierarchy with a static member (a
vector) in which some strings are stored depending on the Class:
class Base { // Abstract
....
typedef std::vector<std::string> nameVector_t;
public:
const nameVector_t& GetNames() { return names; }
protected:
virtual void SetNames()=0,
static nameVector_t names;
};
class House : public Base {
virtual void SetNames() {
names.push_back("Door");
names.push_back("Window");
names.push_back("Roof");
}
};
int main()
{
Base* p = new House;
p->SetNames();
std::cout << p->GetNames[1] << std::endl; // Should print "Window"
}
Is this OK? If not, how can I do something similiar?
Thanks!
vector) in which some strings are stored depending on the Class:
class Base { // Abstract
....
typedef std::vector<std::string> nameVector_t;
public:
const nameVector_t& GetNames() { return names; }
protected:
virtual void SetNames()=0,
static nameVector_t names;
};
class House : public Base {
virtual void SetNames() {
names.push_back("Door");
names.push_back("Window");
names.push_back("Roof");
}
};
int main()
{
Base* p = new House;
p->SetNames();
std::cout << p->GetNames[1] << std::endl; // Should print "Window"
}
Is this OK? If not, how can I do something similiar?
Thanks!