主题:请教
#include<iostream>
#include<string>
using namespace std;
class student{
string name;
public:
student(const string &s):name(s){}
};
void fn(student& s){cout<<"ok\n";}
int main(){
fn(string("jenny"));
}
提示出错:E:\VC文件库\2.cpp(11) : error C2664: 'fn' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'class student &'
A reference that is not to 'const' cannot be bound to a non-lvalue
怎么回事
#include<string>
using namespace std;
class student{
string name;
public:
student(const string &s):name(s){}
};
void fn(student& s){cout<<"ok\n";}
int main(){
fn(string("jenny"));
}
提示出错:E:\VC文件库\2.cpp(11) : error C2664: 'fn' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'class student &'
A reference that is not to 'const' cannot be bound to a non-lvalue
怎么回事