"错误:在'.标记'之前出现预期的主表达式,我不知道为什么
"error: expected primary-expression before '.' token" shows up and I don't know why
我对C++很陌生,我不确定为什么"字符串c = print.say(z(;"会产生错误,如果我把它放在main或while循环中。
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class print {
public:
int x;
string say(int x) {
switch (x) {
case 1: return "text1";
case 2: return "text2";
case 3: return "text3";
default: return "default";} } };
int main() {
int y = 1;
int z = 1;
while (y == 1) {
cin >> z;
string c = print.say(z);
cout << c; } }
没关系,我只需要这样做:
int main() {
print print;
int y = 1;
int z = 1;
while (y == 1) {
cin >> z;
string c = print.say(z);
cout << c; } }
相关文章:
- 为什么constexpr的性能比正常表达式差
- 编译 llvm 3.1 时,为什么会出现错误:在">"标记之前预期主表达式
- 为什么在 while 循环中返回表达式不起作用
- 为什么C++正则表达式这么慢?
- 为什么不能用常量表达式声明数组?
- 为什么'typeid(x) == typeid(y)'的计算结果为 true,其中 'x' 和 'y' 分别是 T 和 T& 类型的 id-表达式?
- 为什么这个正则表达式C++在括号表达式中抛出无效范围异常?
- 为什么这个复合语句作为用大括号和括号括起来的语句序列似乎不是有效的语句表达式
- 为什么新表达式可以正确生成指针类型,即使它应该返回 void*?
- 为什么 Boost:正则表达式没有按预期找到所有结果?
- 为什么带有指针子对象的文字类类型的 constexpr 表达式不能是非类型模板参数
- 为什么'class'和'main'中的相等表达式表现不同?
- 在C++ Lambda 表达式中,为什么人们更喜欢按值捕获而不是作为参数传递?
- 为什么我的 SFINAE 表达式不再适用于 GCC 8.2?
- 针对 std::function 的 lambda 表达式和模板推导:为什么会这样?
- 为什么在template函数广播中把两个extensor表达式加在一起不正确
- 为什么C++中的表达式类型在不同版本之间会发生变化
- 为什么这个涉及重载运算符和隐式转换的C++表达式是不明确的
- 不同的结果在C、C++和Java中得到相同的表达式.为什么
- 没有从值到值的已知表达式&...为什么?