I have created a variable in base class that is a vector of template but I'm not able to access this member from the derived class , can someone explain?
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
/*
*
*/
template <typename T>
class Apple{
protected:
public:
vector<T> vec;
virtual void foo(T node) =0;
};
template <typename T>
class Ball:public Apple<T>{
public:
void foo(T node){
cout<<"hahaha\n";
vec.push_back(node);/* I GET COMPILATION ERROR HERE"vec was not declared in this scope"*/
}
};
int main(int argc, char** argv) {
Ball<int> b;
b.foo(10);
return 0;
}
You have not created any private members in the base class. To resolve the error, you can replace the line which produces compilation error with : Apple::vec.push_back(node); or this->vec.push_back(node)