"[Error] expected unqualified-Id before 'if'"这个代码块是什么意思
what is "[Error] expected unqualified-Id before 'if'" mean in this block of code
我试图衡量作为学校项目的示例,我真的不知道我做错了什么,当然会在功能中添加IF语句,因为它可以使用't呼叫自己
#include <iostream>
using namespace std;
int main(){
struct worker{
int salary;
float taxperc;
int bills;
int home_needs;
int bonus;
bool measure;
void saving(){
float tax = (salary/100)*taxperc;
cout << salary - tax -bills-home_needs << endl;
}
if (measure)
saving();
};
worker me = {50000, 2.5, 150, 3000, 0, true};
}
不确定您要实现的目标,但是您不能在struct
范围级别上具有if
。直接在struct { ... }
中,您只能拥有:
- 成员值(字段)
- 成员功能
而不是常规代码,语句等。您实际上期望执行此类代码?
您的选择是:
- 将
if (measure) { saving(); }
放入另一个成员函数 - 从结构外部的
main
功能中调用saving()
,例如me.saving()
P.S。我强烈建议您也为您的代码缩进,为了可读性。
相关文章:
- 获取英特尔 Kaby Lake 架构上最后一级高速缓存未命中计数的确切代码是什么?
- 这行代码是什么意思
- 此练习的C 代码是什么
- c++ 中的代码是什么意思
- 这个代码是什么意思 std::vector<cv::P oint2f> points[2]
- 这一小堆代码是什么意思
- C++向量,这段代码是什么意思
- 在 c++ 中加减分数的代码是什么
- 验证给定C++编译器是否将源代码读取为 C++11 的快速简单代码是什么?
- DllMain 中钩子回调函数的入口代码是什么
- static_cast<T* 易失性*> - 此代码是什么意思?
- 任务杀死实用程序的退出代码是什么
- GCC 发出的 vtable 汇编代码中的那两个长代码是什么?
- 这C++代码是什么意思?'const ResTable&res = am->getResources();'
- 这个Python切片语句的C++等效代码是什么
- 在链表形成中,在开头添加变量的代码是什么
- MinGW .exe 需要一些 gcc dll 的,不管代码是什么?
- &x 输出到控制台的代码是什么?
- 类型铸造?样板这行cpp代码是什么
- 这行代码是什么意思*((int*)(0))=1;