我有以下代码:
#include <iostream>
class commaNumpunct: public std::numpunct<char> {
protected:
char_type do_decimal_point() const { return ','; }
};
int main(int argc, char** argv) {
std::locale locale;
std::locale locale2(locale, new commaNumpunct());
std::cout.imbue(locale2);
std::cout << 1.43 << std::endl;
return 0;
}
如果我正常编译它:
g++ main.cpp
我明白了:
1,43
正如所料。如果我编译它:
g++ -fno-rtti main.cpp
我明白了:
Program received signal SIGSEGV, Segmentation fault.
__cxxabiv1::__dynamic_cast (src_ptr=src_ptr@entry=0x614c20, src_type=0x7ffff7dcb740 <typeinfo for std::locale::facet>,
dst_type=dst_type@entry=0x7ffff7dcd068 <typeinfo for std::locale::facet::__shim>, src2dst=src2dst@entry=-2) at /build/gcc-multilib/src/gcc/libstdc++-v3/libsupc++/dyncast.cc:72
72 /build/gcc-multilib/src/gcc/libstdc++-v3/libsupc++/dyncast.cc: No such file or directory.
有没有办法以这种方式使用语言环境并同时关闭RTTI?