I have a simple set up:
struct Animal {
protected:
Cry* cry;
};
I can easily access cry in the Constructor of a subclass:
template <typename T>
struct Dog: Animal{
Dog<T>(Cry* ccry) {
cry = ccry;
attacks = Animals::loadAttacks<T>("dog");
};
private:
std::vector<T> attacks;
};
When I try to template the Animal like this:
template <typename T>
struct Animal {
protected:
Cry* cry;
std::vector<T> attacks;
};
I am unable to access the members like this:
template <typename T>
struct Dog: Animal<T> {
Dog<T>(Cry* ccry) {
attacks = Animals::loadAttacks<T>("dog");
cry = ccry;
};
};
The compiler complains about attack and cry not being members. I found the compiler to work with the following code:
template <typename T>
struct Dog: Animal<T> {
Dog<T>(Cry* ccry) {
attacks(Animals::loadAttacks<T>("dog"));
this->cry= ccry;
};
};
but it throws a "Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0" which leads me to believe that the members are not being initialized correctly.
How does one go about this?