O
Old Wolf
I have the following code. One one compiler it compiles OK,
on the other it gives the two warnings shown below, and then
the linker fails because Foo<int>::str is undefined.
Which is correct?
Second question: the compiler won't accept:
static const std::string str = std::string();
Is there any way to achieve that effect with alternative code?
#include <iostream>
template<typename T>
struct Foo
{
static const bool i = false;
static const std::string str;
};
template<typename T>
void foo()
{
std::cout << Foo<T>::str << std::endl;
}
template<typename T>
void bar()
{
if (Foo<T>::i) // "Condition is always false."
foo<T>(); // "Unreachable code."
}
int main()
{
bar<int>();
}
on the other it gives the two warnings shown below, and then
the linker fails because Foo<int>::str is undefined.
Which is correct?
Second question: the compiler won't accept:
static const std::string str = std::string();
Is there any way to achieve that effect with alternative code?
#include <iostream>
template<typename T>
struct Foo
{
static const bool i = false;
static const std::string str;
};
template<typename T>
void foo()
{
std::cout << Foo<T>::str << std::endl;
}
template<typename T>
void bar()
{
if (Foo<T>::i) // "Condition is always false."
foo<T>(); // "Unreachable code."
}
int main()
{
bar<int>();
}