Mar 23, 2008 at 2:28am UTC
Hi everyone.
I have a problem with passing program argument to template class.
program usage:
progname inputFile dataType (for example progname in1.txt double)
so argv[2] is some class name or data type (for example int, double or MyClass)
I have template class:
template <class DT>
class Pair{
public:
Pair(ifstream &in_file){in_file >> _key >> _data;}
.
.
private:
DT _data;
int _key;
};
in main I have:
int main(int argc, char *argv[])
{
.
.
.
ifstream in_file;
in_file.open(argv[1]);
char* dataType = argv[2];
Pair<dataType> pair(in_file);
and here I have error message: "'dataType' is not a valid template type argument for parameter 'DT'"
How can I solve it? i must somehow convert char* dataType(for example double) to legal class name.
Mar 23, 2008 at 8:48am UTC
Don't post the same question in two forums!
Mar 23, 2008 at 9:18am UTC
sorry. can I somehow remove post from here?
Mar 23, 2008 at 6:11pm UTC
I don't think so. You can always edit it, and replace the text with REMOVED.