Hi.I have a piece of code that compiles without even a warning on the borland 5.5 compiler yet complains bitterly when compiling with g++.I've heard that g++ emits more portable code but shouldn't they both be standard compliant?From what i've read in the '98 standard book this should be legal but feel free to prove me wrong.Thanks
#include <iostream>
#include <string>
template <const char* type=NULL> struct asd {
static const char* str;
std::string strng;
asd () : strng(type) {}
~asd () {}
operator std::string () {
return strng;
}
};
template <const char*> const char* asd<>::str="asd";
typedef asd<asd<>::str> Asd;
int main () {
Asd s;
std::cout << std::string(s);
}
G++ spitting fire:
asd.cpp:14:40: error: could not convert template argument ‘0’ to ‘const char*’
asd.cpp:14:43: error: template declaration of ‘const char* str’
asd.cpp:15:17: error: could not convert template argument ‘0’ to ‘const char*’
asd.cpp:15:23: error: template argument 1 is invalid
asd.cpp:15:28: error: invalid type in declaration before ‘;’ token
asd.cpp: In function ‘int main()’:
asd.cpp:19:32: error: invalid conversion from ‘Asd’ to ‘const char*’
asd.cpp:19:32: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]’