R
ratzeel
Hi,
I've two modules in my project. One is a dll and another is an exe.
The dll contains the following template code in one of its header
file.
#ifndef __STACK_HEADER__
#define __STACK_HEADER__
template< class T>
class Stack
{
public:
void push(const T& item);
private:
T arr[MAX];
};
// specialization for int
template<>
void Stack<int>:
ush(const int& item)
{
// push ints..
}
// specialization for float
template<>
void Stack<float>:
ush(const float& item)
{
// push floats..
}
#endif // __STACK_HEADER__
Another module, an exe loads the above dll.
The exe has got two .cpp files.
1.cpp:
void func_1()
{
Stack<int> stack;
stack.push(10);
Stack<float> stack1;
stack1.push(210);
}
2.cpp:
void func_2()
{
Stack<int> stack;
stack.push(10);
Stack<float> stack1;
stack1.push(210);
}
When I build this exe, I'm getting the following errors.
reader1 error LNK2005: "public: void __thiscall Stack<int>:
ush(int
const &)" (?push@?$Stack@H@@QAEXABH@Z) already defined in reader1.obj
reader1 error LNK2005: "public: void __thiscall
Stack<float>:
ush(float const &)" (?push@?$Stack@M@@QAEXABM@Z)
already defined in reader1.obj
Both the exe and the dll are built with /MDd (multi threaded debug
DLL) option.
Any thoughts on how to resolve this multiply defined symbols error
when we specialize.
Thanks....
I've two modules in my project. One is a dll and another is an exe.
The dll contains the following template code in one of its header
file.
#ifndef __STACK_HEADER__
#define __STACK_HEADER__
template< class T>
class Stack
{
public:
void push(const T& item);
private:
T arr[MAX];
};
// specialization for int
template<>
void Stack<int>:
{
// push ints..
}
// specialization for float
template<>
void Stack<float>:
{
// push floats..
}
#endif // __STACK_HEADER__
Another module, an exe loads the above dll.
The exe has got two .cpp files.
1.cpp:
void func_1()
{
Stack<int> stack;
stack.push(10);
Stack<float> stack1;
stack1.push(210);
}
2.cpp:
void func_2()
{
Stack<int> stack;
stack.push(10);
Stack<float> stack1;
stack1.push(210);
}
When I build this exe, I'm getting the following errors.
reader1 error LNK2005: "public: void __thiscall Stack<int>:
const &)" (?push@?$Stack@H@@QAEXABH@Z) already defined in reader1.obj
reader1 error LNK2005: "public: void __thiscall
Stack<float>:
already defined in reader1.obj
Both the exe and the dll are built with /MDd (multi threaded debug
DLL) option.
Any thoughts on how to resolve this multiply defined symbols error
when we specialize.
Thanks....