【发布时间】:2016-01-04 14:21:15
【问题描述】:
我已经定义了这个类:
class Forum{
std::string title;
Thread* threads[5];
在 Forum::Forum 的构造函数中,我想传递一个字符串参数来定义标题(属于字符串类型)
Forum::Forum(string *k) {
int i;
std::strcpy(&title.c_str(),k->c_str());
我在这方面有问题。在这段代码中,我得到一个“需要左值作为一元'&'操作数”错误。 如果我删除 '&' 我会收到错误“从 'const char*' 到 'char*' [-fpermissive] 的无效转换”。
任何想法我将如何设法将参数与 strcpy(或可能使用另一种方法)传递给字符串类型以避免上述错误?
【问题讨论】: