Porting some code from GNU C++ to MS Visual C++... Syntax Error?

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
Hey guys. I haven't seriously used Microsoft Visual C++ in many years, so I'm not familiar with its quirks. I'm using Visual Studio 2010 on Windows 7. My code was originally written in Mac OS X (Unix) using the GNU C++ compiler.

For the most part, I've figured out all the other errors. There's one more thing that's killing my code: a syntax error that I just don't understand.

Here's the line:
Code:
component.push_back((ComponentPixel){i, j});

Here are the errors (all for the same line):
Code:
Error	5	error C2143: syntax error : missing ')' before '{'	
Error	6	error C2059: syntax error : ')'	
Error	7	error C2143: syntax error : missing ';' before '{'	
Error	8	error C2143: syntax error : missing ';' before '}'	
Error	9	error C2059: syntax error : ')'

ComponentPixel is a struct of types {int, int}.
component is of type std::vector<ComponentPixel>

Thanks in advance :)
 
Last edited:

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Maybe like the compiler isn't respecting implicit operator= on your struct.
Code:
Code:
ComponentPixel pixel = {i, j};
component.push_back(pixel);
 

slugg

Diamond Member
Feb 17, 2002
4,723
80
91
Maybe like the compiler isn't respecting implicit operator= on your struct.
Code:
Code:
ComponentPixel pixel = {i, j};
component.push_back(pixel);

That solved it. Really annoying, since I had to change that in 18 different places (two different neighborhood based algorithms). But alas, it works! Thanks!
 

postmortemIA

Diamond Member
Jul 11, 2006
7,721
40
91
FYI MinGW (gcc compiler for Windows) has greatly evolved over the years, and it is probably easier to use similar gcc-based toolchain to port code.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
*Sigh* MinGW and msys. Sometimes it's easier; sometimes it's not. It's usually easier for CPU-only code without a lot of external libraries. But I guess you got it working.
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
*Sigh* MinGW and msys. Sometimes it's easier; sometimes it's not. It's usually easier for CPU-only code without a lot of external libraries. But I guess you got it working.

Yep. If you are using open sourced libraries, MingW is generally good. If you want to use MS libraries, you've got a lot of hurting coming. DirectX 10 doesn't mix well with MingW