ok lets correct this:
Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template<typename T>
class AA{
protected:
vector<T> vx;
public:
AA(vector<T>& v);
};
template<typename T>
AA<T>::AA(vector<T>& vec){
vx.reserve(vec.size());
copy(vec.begin(),vec.end(),back_inserter(vx));
}
// my derived class
template<typename T>
class B : public AA<T> { // corrected
public:
B(vector<T>& v);
void print_r(T x);
};
template<typename T>
B<T>::B(vector<T>& vec){
AA<T> a(vec);
}
template<typename T>
void B<T>::print_r(T x){
cout << this->vx[x] << endl;
}
int main (){
vector<int> V(10,6);
int k = 4;
B<int> b(V);
b.print_r(k);
}
now i get an error :
Code:
t$ g++ -g -std=c++0x -o class_1 class_1.cpp
class_1.cpp: In constructor ‘B<T>::B(std::vector<T>&) [with T = int]’:
class_1.cpp:51:13: instantiated from here
class_1.cpp:38:23: error: no matching function for call to ‘AA<int>::AA()’
class_1.cpp:38:23: note: candidates are:
class_1.cpp:20:1: note: AA<T>::AA(std::vector<T>&) [with T = int]
class_1.cpp:20:1: note: candidate expects 1 argument, 0 provided
class_1.cpp:9:7: note: AA<int>::AA(const AA<int>&)
class_1.cpp:9:7: note: candidate expects 1 argument, 0 provided
class_1.cpp:9:7: note: AA<int>::AA(AA<int>&&)
class_1.cpp:9:7: note: candidate expects 1 argument, 0 provided