J
John
Hi,
I have the code below and am using gcc version 4.4.4, When I compile
only main.cpp I get no error, but when I compile both main.cpp and
ClassA.cpp, I get the following
ClassA.cpp
.text+0x0): multiple definition of `bool
ClassA::Test<bool>(bool&)'
/tmp/ccC10DId.o:main.cpp
.text+0x0): first defined here
collect2: ld returned 1 exit status
Can someone explain why I am getting this error and how to solve it?
Thanks,
John
== FILE main.cpp ==
#include "ClassA.hpp"
int main()
{
bool data;
bool has = ClassA::Test(data);
return 0;
}
== FILE ClassA.hpp ==
#ifndef __CLASSA_HPP__
#define __CLASSA_HPP__
class ClassA
{
public:
template <typename T> static bool Test(T& data);
};
template <typename T> bool ClassA::Test(T& data)
{ return true; }
template <> bool ClassA::Test(bool& data)
{ return false; }
#endif
== FILE ClassA.cpp ==
#include "ClassA.hpp"
int abc_;
I have the code below and am using gcc version 4.4.4, When I compile
only main.cpp I get no error, but when I compile both main.cpp and
ClassA.cpp, I get the following
/tmp/cc8inIcc.o: In function `bool ClassA::Test<bool>(bool&)':g++ main.cpp ClassA.cpp
ClassA.cpp
ClassA::Test<bool>(bool&)'
/tmp/ccC10DId.o:main.cpp
collect2: ld returned 1 exit status
Can someone explain why I am getting this error and how to solve it?
Thanks,
John
== FILE main.cpp ==
#include "ClassA.hpp"
int main()
{
bool data;
bool has = ClassA::Test(data);
return 0;
}
== FILE ClassA.hpp ==
#ifndef __CLASSA_HPP__
#define __CLASSA_HPP__
class ClassA
{
public:
template <typename T> static bool Test(T& data);
};
template <typename T> bool ClassA::Test(T& data)
{ return true; }
template <> bool ClassA::Test(bool& data)
{ return false; }
#endif
== FILE ClassA.cpp ==
#include "ClassA.hpp"
int abc_;