Then, I decided to specialize some of the template class methods. I did it
in some.h file, of course, where the template itself is located.
When I compile, it gives me linker error for every file that imports some.h,
saying that these specialized methods already defined in xxx.obj (the first
file to cmpile, which includes some.h).
Are there some specific rules about that that I might be missing?
Below is the code for template
// template to set temporally some Acad global variables
template <typename T> class TemporarilySet
{
public:
TemporarilySet(const CString acadGlobalVarName,
const T tempValue)
{
AcadGlobalVarName = acadGlobalVarName;
OldValue = getVar();
setVar(tempValue);
}
~TemporarilySet()
{
setVar(OldValue);
}
protected:
int setVar(T value);
T getVar();
private:
CString AcadGlobalVarName;
T OldValue;
};
// template specializations
template <> int
TemporarilySet<int>::getVar()
{
return log_GetIntVar(AcadGlobalVarName);
}
template <> int
TemporarilySet<int>::setVar(int value)
{
return log_SetIntVar(AcadGlobalVarName, value);
}
template <> CString
TemporarilySet<CString>::getVar()
{
return log_GetStringVar(AcadGlobalVarName);
}
template <> int
TemporarilySet<CString>::setVar(CString value)
{
return log_SetStringVar(AcadGlobalVarName, value);
}
eg:
#ifndef ME
#define ME
your code follows here...
#endif
Ramesh
"andru123" <andru123 at hotmail dot com> wrote in message
news:eG2fLBd0CHA.2184@TK2MSFTNGP09...
"ramesh" <k...@srasys.co.in> schreef in bericht
news:#VxsfFd0CHA.2204@TK2MSFTNGP09...
They need to be either identified as inline or moved to a single cpp
file.
Otherwise, the compiler generates the specializations in each cpp file
that includes the header file, which is no different from multiple
definitions of a non-template.
--
Craig Powers
MVP - Visual C++