#include <iostream>
using namespace std;
int main()
{
struct calcvaribles;
{
int a;
int b;
int sum;
};
struct introstructions;
{
char ab[35];
string ac;
};
introstructions outline;
outline.ab = "welcome to my calculator program!";
outline.ac = "please enter any [One] number in the
terminal";
return 0;
}
错误信息:
aggregate main():: introstructions outline有不完整的类型,无法定义
Introstructions概述。
struct
里宣布main
s?将它们移到全球范围内。char
数组:outline.ab = "welcome to my calculator program!";
。相反,使用const char*
,或者更好的是,如下所示,char
数组声明,std::string
,但不要忘记#include <string>
。您的代码中的问题是您在;
名称后面包含struct
:
struct calcvaribles;
struct introstructions;
以下应该有效:
#include <iostream>
#include <string>
using namespace std;
int main() {
struct calcvaribles {
int a;
int b;
int sum;
};
struct introstructions {
string ab;
string ac;
};
introstructions outline;
outline.ab = "welcome to my calculator program!";
outline.ac = "please enter any [One] number in the terminal";
return 0;
}
在这种情况下,C ++语言对您没有帮助,因为编译器以完全不同的方式解释代码。
#include <iostream>
using namespace std;
int main()
{
struct calcvaribles;
由于上面一行末尾的分号,编译器将其读作:
有一个名为calcvaribles
的结构。目前尚不清楚结构具有哪些字段,而是在其他地方定义。在任何情况下,结构的名称都是已知的,如果您声明一个指向该结构的类型指针的变量,则允许从no开始。
{
这个开口支撑意味着:
新的范围从这里开始。在此范围内声明的任何变量仅在相应的}
之前可用。
int a;
int b;
int sum;
这些是正常变量的声明,而不是结构域(你想要的)。这些变量不执行任何操作,它们没有分配值,并且根本不读取它们的值。总之,这三条线是一个很大的“无所事事”块。
};
范围在此结束。从现在开始,变量qazxsw poi,qazxsw poi和qazxsw poi已不复存在。
分号也没用。这是一个空洞的陈述。允许但没用。
a
b
类型也是如此。
如果您在sum
函数之外编写struct introstructions;
{
char ab[35];
string ac;
};
introstructions outline;
outline.ab = "welcome to my calculator program!";
outline.ac = "please enter any [One] number in the
terminal";
return 0;
}
定义,编译器会给您一个“语法错误”消息。也许你先做了,并修复错误信息,你把所有东西都移到了main函数中。
不幸的是,仅仅因为这些尾随的分号,你编写的代码仍然编译但意味着完全不同的东西。但是没有解决方法。