I am using visual studio VC6.0 as the compiler for below programme
and getting a strange error written in the main function before the line
causing the same
Even moved the class and template memeber functions in a header file
making them inline but the same error persists
# include <iostream>
using namespace std ;
class templateArgument
{
public:
void snapShot ()
{
cout<<endl<<"I am snapShot::templateArgument () "<<endl;
}
};
// -------------Template Class--------------
// Purpose is to pass class templateArgument as <T>
template<class T>
class seedGenerator
{
My mistake
templateArgument2 is templateArgument
The original problem still persists even moving all template classes and definitions
to header file and inlining them (VC6.0 environment)
The actual code now is
# include <iostream>
using namespace std ;
class templateArgument
{
public:
void snapShot ()
{
cout<<endl<<"I am snapShot::templateArgument () "<<endl;
}
};
// -------------Template Class--------------
// Purpose is to pass class templateArgument as <T>
template<class T>
class seedGenerator
{
It is a problem in VC 6.0
Yes - he needs to update his compiler as suggested by Hammurabi
There is a solution if you are stuck with VC6.0 as follows:
1. Move the implemation of the seedGeneratorCreator::createSeed to inside the class, and make it take a parameter of type T. Like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//---- Class having template function --------------
// Non template class having template member function
class seedGeneratorCreator
{
public:
//implementation now inside class and takes a parameter of type T
template<class T>
seedGenerator<T> createSeed (T t)
{
///T object ; no longer required
return seedGenerator<T> (t) ;
}
};
Now call it like this
1 2 3 4 5 6 7 8 9 10
int main()
{
seedGeneratorCreator factory ;
//should no longer give error C2275
factory.createSeed( templateArgument() ); //call with object of required type
return 0;
}
The best solution however is to upgrade your compiler - VC6.0 has shakey template support.