Click here to Skip to main content
15,887,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 23-Jan-18 21:45pm
v2

1 solution

C++
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
C++
client[i].member1 = -1;
client[i].socket = INVALID_SOCKET;
or
C++
// Create and initialise an instance to be copied
ClientType emptyClient = { -1, INVALID_SOCKET };
// ...
client[i] = emptyClient;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900