C++:VS遇见的错误(持续)

来源:互联网 发布:昆山有java培训机构吗 编辑:程序博客网 时间:2024/05/22 10:53

1:有的时候报错:missing a ";"

     很有可能需要( )或者[ ],但你却给出了{ }


2:error 2143: missing ')'

    写成了while (auto it = S.begin(); it !=S.end(); ++i )

应是:for (auto it = S.begin(); it !=S.end(); ++i )


3:error C2143: syntax error : missing ';' before 'type'

可能是因为不能是for(int i = 0; i< LIMIT; ++i),应该改正为int i; for(i = 0; i< LIMIT; ++i)

也可能是在一个{ }块中,变量的声明位置不对。如

{

.......

int i;

for(i = 0; i< LIMIT; ++i)

.......

}

就会出错,应该改成

{

int i;

.......

for(i = 0; i< LIMIT; ++i)

.......

}


4.error C2143: syntax error : missing ')' before ';'

int main(){FILE* f;int tmp;f = fopen("data.txt","r");while((fscanf(f," %d", &tmp);)!=EOF)printf("%d\n", tmp);fclose(f);return 0;}

在第5,6行都报了这个错

其实是因为第6行的while()中多了一个;

改正后错误消失


4.error C2027: use of undefined type

解释是:STNode这个类的使用放在了定义之前,编译系统不能识别。如果没有其他的类之间的调用的话,你直接把STNode的定义放在使用该类的那个类定义之前。或者加上前向引用声明。不过需要注意的是前向引用声明后,只能定义声明类的指针或是引用。


我出现这个问题是这样:
一个1.h文件中包含了struct Item的声明
一个1.c文件中包含了struct Item的定义
一个main.c中包含了1.h

int main(){Dictionary table = (Dictionary) malloc(sizeof(struct Dic));CreateDictionary(table, 256);//printf("item%d is %d",100, table->TheItems[100].Index);return 0;}
结果在第一句出现C2027的错误。
后来我将struct Item的定义复制到main.c的main之前,就解决了

4.warning C4715: 'compress' : not all control paths return a value

你在函数的最外层再写一个return 0;  //就不会警告了,而且对程序也不会用影响
加上了return 0;之后不会出现警告了


5.error C2146:

我这里的错误发生在头文件中。原因是头文件中用到了ElementType类型,但是没有这个类型的定义

解决办法是#define ElementType int或者是把ElementType类型的头文件包含进来


0 0