Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Please help with pointers!!!

Status
Not open for further replies.

Elina

Computer
Jun 7, 2005
1
I have this code and I get this error messages, when I try to initialize mypointer:
E2238 Multiple declaration for 'identifier'
E2344 Earlier declaration of 'identifier'
E2141 Declaration syntax error

//---------------------------------------------------------
#include <vcl.h>
#include <stdlib.h>
#include <math.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

struct sar
{
int x;
int y;
int mgn;//magnitude
sar *nextpx;
sar *nextline;
};

sar *mypointer=new sar;

//compiler shows this is a wrong line
mypointer->mgn=9;


//---------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
struct sar
{
int x;
int y;
int mgn;//magnitude
sar *nextpx;
sar *nextline;
};

sar *n1=new sar;
n1->mgn=9;
}
//---------------------------------------------------------void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
exit(0);
}
//---------------------------------------------------------


 
Replies continue below

Recommended for you

This code needs to sit in a routine
Code:
  sar *mypointer=new sar;
  
  //compiler shows this is a wrong line
  mypointer->mgn=9;
 
Hello Elina.

First of all, I think that sar should be declared only once. I guess it could be global declaration as it is in your code.

And i'm not sure, but i think that operator new is used to allocate memory for classes, not for the other types.
In that case use memory allocation functions, for example:
Code:
sar *mypointer=(sar*) malloc(sizeof(sar));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor