Hi,
The following class decide which type is in the current instance and itialize depends on this information.
The problem:
When make an instance with any pointer type, a compilation error occures: cannot convert from 'char' to '...*'.
I thought might be a solvation that dont compile the char initialization part if a pointer type has come, but I doubt that could solve with conditional compilation.
Is anyway a solution for this problem?
Thanks
Arepi
Code:
The following class decide which type is in the current instance and itialize depends on this information.
The problem:
When make an instance with any pointer type, a compilation error occures: cannot convert from 'char' to '...*'.
I thought might be a solvation that dont compile the char initialization part if a pointer type has come, but I doubt that could solve with conditional compilation.
Is anyway a solution for this problem?
Thanks
Arepi
Code:
Code:
#include <iostream>
#include <typeinfo>
#include <string>
using namespace std;
template<class type>
class IdInputTypes{
public:
IdInputTypes();
protected:
type Variable;
const type_info& ClassType1;
string ClassType1Name;
};
template<class type>
IdInputTypes<type>::IdInputTypes() : ClassType1(typeid(type)) {
ClassType1Name = ClassType1.name();
if(ClassType1Name.find("*") != ClassType1Name.npos){
Variable=NULL;
cout << "The type of this object is pointer and initialized with NULL" << endl;
}
else if(ClassType1Name=="string" || ClassType1Name=="char"){
Variable=(char)"";
cout << "The type of this object is " << ClassType1Name << "and initialized with '' '' "<< endl;
}
else{
Variable=0;
cout << "The type of this object is a number type and initialized with 0" << endl;
}
}
void main(void){
IdInputTypes<double *> *idp;
idp=new IdInputTypes<double *>;
delete idp;
cin.get();
}
Comment