我的类结构如下:的非const引用无效初始化成从临时
Test_Camera.h:
class Test_Camera : public Camera_Interface {
public:
Test_Camera (string const& aName);
...
Test_Camera.cpp
Test_Camera::Test_Camera(string const& aName) : Camera_Interface(0, 0, 0, 0), name(aName)
在我的代码实例化一个Test_Camera
对象我有2个场景。第一个编译好,但第二个没有,我不明白为什么。
Test_Camera cam ("cam"); // This compiles
Test_Camera& cam ("cam"); // This does not compile
当我尝试编译第二个例子中,我得到一个错误:
error: invalid initialization of non-const reference to type 'Test_Camera&' from a temporary of type 'const char*'
我也试过:
string name = "cam";
Test_Camera& cam (name); //does not compile
对于[ints](http:// ideone),您会得到相同的错误消息.com/Dlpinm) – Default