public:
string str;
Test(string& str){
this->str=str;
cout<<"constructor"<<endl;
}
};
int main() {
Test t="test";
return 0;
}
In this code I get the error "..\src\Test.cpp:30:9: error: conversion from 'const char [5]' to non-scalar type 'Test' requested "
?
Why is then the following code ok?
#include <iostream>
using namespace std;
class Test{
public:
string str;
Test(string str){
this->str=str;
cout<<"constructor"<<endl;
}
Test(const Test &test){
cout<<"copy constructor"<<endl;
this->str=test.str;
}
};
int main() {
Test t=Test("test");
return 0;
}