linux编译mysql报无法将左值_无法将'std::ostream {aka std::basic_ostream

首先:声明函数接受const Letter&,然后定义你的成员静态变量并在使用之前转发声明或定义运算符

std::ostream& operator <

class RandomWordGenerator {

public:

RandomWordGenerator() {

vowels.push_back(Letter('A'));

}

static Word generate() {

std::cout << vowels.front() << std::endl; // the error pops here

Word w(std::string("test"));

return w;

}

public:

static std::vector vowels;

static std::vector consonants;

};

std::vector RandomWordGenerator::vowels;

std::ostream& operator <

return os << l.inner(); // a std::string

}在使用它们之前声明或定义运算符和函数既是一种很好的编程实践,也是强制类型安全的强制要求:编译器需要知道它处理的类型以及整个签名。有关更全面的解释,我建议您阅读以下文章:https://stackoverflow.com/a/4757718/1938163

请注意,您也可以将该函数声明为友元函数,但这里有一个问题:friend declaration not forward declaring

std::ostream& operator <

return os << l.inner(); // a std::string

}

class RandomWordGenerator {

public:

RandomWordGenerator() {

vowels.push_back(Letter('A'));

}

friend std::ostream& operator <

static Word generate() {

std::cout << vowels.front() << std::endl; // the error pops here

Word w(std::string("test"));

return w;

}

public:

static std::vector vowels;

static std::vector consonants;

};

std::vector RandomWordGenerator::vowels;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值