Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bad pointer declaration?

Status
Not open for further replies.

RandallW

Programmer
Jun 24, 2000
18
0
0
US
Here's what I have in my main function:

int *first = 29, *second = 50;

Attempting to compile, there is error C2440: cannot convert from 'const int' to 'int *'

What am I doing wrong?

[sig][/sig]
 
I dont think you can declare like that, you need to do like this

int *first, *second;

oh also, yer assigning a literal to a pointer, where it may not have an address, what you need to do is something like this

int *first = new int;
*first = 23;

that way a memory allocation has been made, then you just assign that value into the already allocated memory.
[sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
I tried using
Code:
  int *first, *second; [code]

That was my first attempt, it also gave an error, but I think it appeared during my build attempt.

Well, i'll try that other part you had. [sig][/sig]
 
Okay, I tried
Code:
 int *first = new int;
It compiles okay, but when I attempt to build the executable, I get &quot;error LNK2001: unresolved external symbol _wWinMain@16&quot;
When I check the explanation of the error, i'm told this happens if I don't have an entry point to wWinMainCRTStartup, and I need to type this value into the Linker Settings dialog box; I found what seems to be this box, and this value is already there.
Perhaps my problem is something else? I accidentally linked a different file to my project; in my project settings I have clicked the box to exclude it from the build....how do I completely get rid of it? [sig][/sig]
 
I don't know what is this question about. If you want to point the address 29 you need declare like this
int* first=(int*)int; [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top