Learning the win32 api & keep getting errors

Asked By 0 points N/A Posted on -
qa-featured

Hi,

I'm learning the win32 api and i keep getting errors at one of my function prototypes where I'm trying to pass a reference variable of type POINT.

Here are the error messages.

error C2143: syntax error : missing ')' before '&'
error C2143: syntax error : missing '{' before '&'
error C2059: syntax error : '&'
error C2059: syntax error : ')'

Prototype

The function.

HWND CreateButton (HWND hwnd, wchr-t* name, int identifier, POINT& pt);

{

….

}

I've played around referencing both classes and structs 20 min before I wrote this post. Just in case i misunderstood something and massively failed. They worked and compiled perfectly.

Question is what I'm doing wrong.

SHARE
Best Answer by mendoza_rys
Answered By 5 points N/A #87174

Learning the win32 api & keep getting errors

qa-featured

In the function you should not have a ";" at the end of it.

The function.

Other than that your code seems fine enough to compile.  You may want to check your compiling settings.  Sometimes, people tend to compile C++ code with the C compiler. 

Do ensure that you did not commit such a mistake.

Best Answer
Best Answer
Answered By 0 points N/A #87176

Learning the win32 api & keep getting errors

qa-featured

error C2143: syntax error : missing ')' before 'type'

When programming in Visual Studio, if you happen to run across this error while trying to compile C code, one thing to check on is whether or not you're declaring your local variables inline.  For whatever reason, Visual Studio hates this and issues a syntax error for the next line of code.  One that's of no use whatsoever in helping to figure out what to do.

So, for example, if you have a function like:

int foo(int x)
{
    assert(x != 0);
    int y = 4/x;
    return y;
}

You would need to rewrite your code like this:

int foo(int x)
{
    int y;
    assert(x != 0);
    y = x/4;
    return y;
}

error C2059: syntax error : 'type'

The data type you're passing into calculate_total is wrong. C++ is seeing it as a pointer to an int. You're passing in a two dimensional array. You have to make the input type for your calculate_total function match the type of your array.

Also, all those extra []'s are invalid syntax. When passing in a variable defined as an array, pass in only the variable name.

example
// Invalid function call
f(myArray[]);

// Valid function call
f(myArray);

Inside of the actual function, what are you trying to do? Are you trying to modify an element of exam1, exam2, and exam3 to the value of exam[100][3]?

You're also missing the declaration of the array int exam[100][3]. I don't see it anywhere in your code.

And in the return of calculate_total, your return statement is malformed. You can only return one value, unlike Python where that would return a triple containing three elements.

Related Questions