开发者

Problem with pointers

开发者 https://www.devze.com 2022-12-29 03:26 出处:网络
OK, i have a strange problem. I have this piece of code: int *p; int test;开发者_高级运维 p=&test;

OK, i have a strange problem. I have this piece of code:

int *p;
int test;开发者_高级运维
p=&test;

In Visual C++ express, in my exsisting project, I get this error:

missing type specifier - int assumed.
'p' : 'int' differs in levels of indirection from 'char *'
'initializing' : cannot convert from 'char *' to 'int'

But when i create new project, same code is fine. Whats the problem please?


Something preceding this code may be breaking things (more context might help). Perhaps test is a macro that wreaks havoc with the meaning of your code.


If the same code on different projects produces different results, I guess you can assume the problem isn't with the code, but with the project.

I suggest you make a diff between the two project files to have a quick look over what could be wrong.


Have you placed that code inside a function? You cannot write arbitrary C++ code outside of functions.

int main() {
    int *p;
    int test;
    p=&test;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消