I have the following class definition:
template<typename T> class Point { private: T px, py; public: Point(T x, T y): px(x), py(y) { std::cout << "created " << x << ":" << y <<std::endl; }; T x() const { return px; }; T y() const { return py; }; };
from which I get specializations for example
class PointScreen: public Point<int> { using Point::Point; };
When I compile this in clang++ , I don't get any warnings / errors, but the constructor is not called:
#include <iostream> // definitions from above int main() { std::cout << PointScreen(100, 100).x() << std::endl; return 0; }
This returns a random value (as well as no debug output "created ..."). The value returned, for example, x() , is obviously "undefined".
I just tried the same in g++ here , and there I get the expected result. Is this a problem with clang++ or am I having a code error?
My clang version: Ubuntu version clang 3.0-6ubuntu3 (tags / RELEASE_30 / final) (based on LLVM 3.0). I am compiling with -std=c++11 -Wall .
source share