i have a small templatized class which just checks for object sizes of different object types: (note: i am compiling with visual studio 2017 cl compiler). All i wanted was to instantiate the template partially and fully. But i am getting compiler error.
template <class T1, class T2>
class Templatized {
private:
int m_counter;
string m_classname;
public:
//c-tor
Templatized() :counter(0), classname(static_cast <string> ("Templatized")) {}
int get_counter() {
return m_counter;
}
string know_class_name() {
return m_classname;
}
bool is_bigger_name(T1 one, T2 two) {
return ((one.know_class_name()).length() > (two.know_class_name()).length());
}
bool is_bigger_object_size(T1 one, T2 two) {
return (sizeof(one) > sizeof(two));
}
//variadic template
~Templatized (){
}
};
class Int_class {
private:
int var1;
public:
int square_int() {
return var1 * var1;
}
string know_class_name() {
return static_cast <string> ("Int_class");
}
};
class Float_class {
private:
float m_var_f;
public:
float double_float () {
return 2.0f * m_var_f;
}
string know_class_name() {
return static_cast <string> ("Float_class");
}
};
and here are the client code, but i am not able to compile them:
Templatized <Int_class, Float_class> templatized;
Int_class intclass;
Float_class floatclass;
cout << "is int class object size is smaller: "
<< templatized.is_bigger_object_size(intclass, floatclass) << endl;
cout << "Has IntClass bigger name: "
<< templatized.is_bigger_name(intclass, floatclass) << endl;
The compiler cries with following error:
1>d:\code\integration\inc\Templates.hpp(14): error C2614: 'Templatized<Int_class,Float_class>': illegal member initialization: 'counter' is not a base or member
1>d:\code\integration\inc\Templates.hpp(14): note: while compiling class template member function 'Templatized<Int_class,Float_class>::Templatized(void)'
1>D:\code\integration\client\integrationClient.cpp(63): note: see reference to function template instantiation 'Templatized<Int_class,Float_class>::Templatized(void)' being compiled
1>D:\code\integration\client\integrationClient.cpp(63): note: see reference to class template instantiation 'Templatized<Int_class,Float_class>' being compiled
Aucun commentaire:
Enregistrer un commentaire