A
Ares Lagae
Consider this code fragment:
#include <iostream>
template <class T>
class Foo
{
public:
T m_f;
Foo(T f) : m_f(f) {}
//Foo(const Foo & foo) : m_f(foo.m_f) {}
static const Foo CONST;
};
template <class T>
const Foo<T> Foo<T>::CONST = Foo(T(1));
class Bar
{
public:
Foo<float> m_foo;
Bar() : m_foo(Foo<float>::CONST)
{
std::cout << "Foo.m_f = " << m_foo.m_f << std::endl;
}
};
Bar bar;
int main(int argc, char * argv[])
{
Bar bar;
return 0;
}
When executed, it prints
Foo.m_f = 0
Foo.m_f = 1
but according to the c++ standard, (i think) it should print
Foo.m_f = 1
Foo.m_f = 1
strangly, when the copy constructor
//Foo(const Foo & foo) : m_f(foo.m_f) {}
is uncommented, it prints
Foo.m_f = 1
Foo.m_f = 1
Is this a bug ?
Best regards,
Ares Lagae
#include <iostream>
template <class T>
class Foo
{
public:
T m_f;
Foo(T f) : m_f(f) {}
//Foo(const Foo & foo) : m_f(foo.m_f) {}
static const Foo CONST;
};
template <class T>
const Foo<T> Foo<T>::CONST = Foo(T(1));
class Bar
{
public:
Foo<float> m_foo;
Bar() : m_foo(Foo<float>::CONST)
{
std::cout << "Foo.m_f = " << m_foo.m_f << std::endl;
}
};
Bar bar;
int main(int argc, char * argv[])
{
Bar bar;
return 0;
}
When executed, it prints
Foo.m_f = 0
Foo.m_f = 1
but according to the c++ standard, (i think) it should print
Foo.m_f = 1
Foo.m_f = 1
strangly, when the copy constructor
//Foo(const Foo & foo) : m_f(foo.m_f) {}
is uncommented, it prints
Foo.m_f = 1
Foo.m_f = 1
Is this a bug ?
Best regards,
Ares Lagae