Visual C++ Express's Unhelpful Error Message

closed account (zb0S216C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main( )
{
      int Base( 10 );
      int *Target( &Base );
      int **Pointer( &Target ); // error C2059: syntax error : '&'

      cin.get( );

      return 0;
}


As you can see, the above error is not even remotely helpful. Can anybody else figure out what I've done wrong?

I've worked with pointer-to-pointers before and never encountered this problem.
closed account (zb0S216C)
Update: Never mind. The problem was the constructor of **Pointer. I had to assign *Target to **Pointer through assignment, not initialization.
Last edited on
Why are you treating int, int*, and int** as if they are classes? I think maybe it doesn't like that in the case of an int** and it's giving you an odd error because this was never expected.
Last edited on
closed account (zb0S216C)
Why are you treating int, int*, and int** as if they are classes?

I was calling the constructor of each instance of int. This is not illegal. It is illegal to initialize a pointer-to-a-pointer using the constructor( I know that now ).

...and it's giving you an odd error because this was never expected

Compiler errors are generally given when coders make errors, which are unexpected to compilers.
Last edited on
Your code is valid and compiles on my VC++ 2008 Express Edition...I honestly don't know what else to say.
Last edited on
closed account (zb0S216C)
I'm running Visual C++ Express 2010. I still don't know why it won't let me initialize **Pointer with the constructor.
It might just be purely a syntax error

would int (**Pointer)(&Target); make more sense?
would int (**Pointer)(&Target); make more sense?


That looks more like a function pointer than a normal pointer.

I don't see any reason why int **Pointer( &Target ); shouldn't work. Seems awfully strange.
@ Dish - Thats what I thought at first.
So I tested it like this:
1
2
3
      
       int (**Pointer)(&Target);//
      Pointer = &Target; // 

It compiled and the The second line didn't crash and burn as it would have done if
it was a function pointer
and cout << Target << " " << *Pointer << endl; gave the same values.

I still can't quite understand why int **Pointer( &Target ); doesn't work -
but I assume the ** coupled with the () constructor throws the normal compiler
parsing as it probably expects a single type - putting the (**) gets rid of any ambiguity.

DISCLAIMER
The above explaination is pure guesswork.
I did that in MSVC - I'll see what MINGW does.
Last edited on
closed account (zb0S216C)
Seems awfully strange.

Could this be a bug?
Tried it in MINGW compiler and it is happy with both
int **Pointer( &Target ); and int (**Pointer)(&Target);


So it looks like Framework has found some sort of bug in MSVC
(and my explaination completely off the mark).
Topic archived. No new replies allowed.