INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Please help with pointers!!!

Please help with pointers!!!

(OP)
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);
}
//---------------------------------------------------------


RE: Please help with pointers!!!

This code needs to sit in a routine

CODE

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

RE: Please help with pointers!!!

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));

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close