方案编制以克++但是退出接头的错误,在海湾合作委员会
题
我想出来的 解决方案 来一个 有关问题的专门类模板.
这个代码有一个汇编现在g++,但引发了接头时的错误汇编与海湾合作委员会.是什么原因这些错误?
$ g++ traits2.cpp
$ gcc traits2.cpp
/tmp/ccI7CNCY.o: In function `__static_initialization_and_destruction_0(int, int)':
traits2.cpp:(.text+0x36): undefined reference to `std::ios_base::Init::Init()'
traits2.cpp:(.text+0x3b): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccI7CNCY.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
该traits2.中国共产党的文件中包含的上述 解决方案 与emtpy主()function:
#include <iostream>
using namespace std;
// A default Traits class has no information
template<class T> struct Traits
{
};
// A convenient way to get the Traits of the type of a given value without
// having to explicitly write out the type
template<typename T> Traits<T> GetTraits(const T&)
{
return Traits<T>();
}
template <int major, int minor> struct A
{
void f()
{
cout << major << endl;
}
};
// Specialisation of the traits for any A<int, int>
template<int N1, int N2> struct Traits<A<N1, N2> >
{
enum { major = N1, minor = N2 };
};
template <> struct A<4,0>
{
void f()
{
cout << "Specialized:" << GetTraits(*this).major << endl;
}
};
int main(int argc, char * argv[] )
{
/*
A<4,0> p;
A<1,2> p2;
p.f();
p2.f();
*/
return 1;
}
解决方案
在用gcc编译,C ++库不能由缺省链接英寸总是与克++生成C ++代码。
其他提示
如果你想看到自己的区别,尝试两个版本与-v标志
$ g++ -v traits2.cpp
$ gcc -v traits2.cpp
这会显示每个从代码顶部可执行的步骤,包括被添加的库。
您的代码是C ++,因此它必须与克编译++,C ++编译器,而不是GCC,C编译器。
不隶属于 StackOverflow