Visual Studio 2012阵列错误 [英] Visual studio 2012 array error
本文介绍了Visual Studio 2012阵列错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的节目中出现了一个荒谬的错误。在Visual Studio 2012专业版中,以下代码片段给出如下错误:
for(int i = 0; i< MAX_CLIENTS; i ++)
{
client [i] = {-1,INVALID_SOCKET};
}
错误是;
1 IntelliSense:预期表达式
错误C2143:语法错误:缺少';'之前'}'
错误C2059:语法错误:'{'
我尝试了什么:
我试图更改项目属性中的某些内容但它没有如果你之前遇到过这样的描述问题,请帮助我
解决方案
client [i] = { - < span class =code-digit> 1 ,INVALID_SOCKET};这是初始化结构的语法,但是您尝试设置现有结构的元素。
您必须使用类似
client [i] .member1 = - 1 跨度>;
client [i] .socket = INVALID_SOCKET;或
// 创建并初始化要复制的实例
ClientType emptyClient = { - 1 , INVALID_SOCKET};
// ...
client [i] = emptyClient;
Hi, I'm getting a ridiculous mistake in my program. In the Visual Studio 2012 professional version, the following code fragment gives an error like this:
for (int i = 0; i < MAX_CLIENTS; i++) { client[i] = { -1, INVALID_SOCKET }; }
Error is;
1 IntelliSense: expected an expression error C2143: syntax error : missing ';' before '}' error C2059: syntax error : '{'
What I have tried:
I tried to change something in the project properties but it did not work well If you have been experiencing problems with such a description before, please help me
解决方案
client[i] = { -1, INVALID_SOCKET };
That is the syntax to initialise a structure but you are trying to set the elements of an existing structure.
You have to use something like
client[i].member1 = -1; client[i].socket = INVALID_SOCKET;
or
// Create and initialise an instance to be copied ClientType emptyClient = { -1, INVALID_SOCKET }; // ... client[i] = emptyClient;
这篇关于Visual Studio 2012阵列错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文