Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. struct type redefinition error

struct type redefinition error

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    boon kian
    wrote on last edited by
    #1

    Hi all, I have a vc problem which i am unable to think of a solution. so can anyone help ?? i have a data type as follow: typedef struct complextag { double dRe; double dIm; } COMPLEX; and i have 3 classes which need this data type. (main class, class A and class B). The main class will have to interact with class A and class B and pass a COMPLEX variable to them. Hence i have put the "typedef struct complextag" in the class A and class B header. I also include the class A and class B header in class main. However when i compile the program, vc complaint of this "error C2011: 'complextag': 'struct type redefinition' is there a way to solve this prob ?? or is there a way to make the COMPLEX data type to be universal like "int" or "float" ??? Thank you very much for the kind attention.

    PJ ArendsP S B 3 Replies Last reply
    0
    • B boon kian

      Hi all, I have a vc problem which i am unable to think of a solution. so can anyone help ?? i have a data type as follow: typedef struct complextag { double dRe; double dIm; } COMPLEX; and i have 3 classes which need this data type. (main class, class A and class B). The main class will have to interact with class A and class B and pass a COMPLEX variable to them. Hence i have put the "typedef struct complextag" in the class A and class B header. I also include the class A and class B header in class main. However when i compile the program, vc complaint of this "error C2011: 'complextag': 'struct type redefinition' is there a way to solve this prob ?? or is there a way to make the COMPLEX data type to be universal like "int" or "float" ??? Thank you very much for the kind attention.

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      One way ( I am sure there are others ) is to wrap the declaration in an #define macro. That way it will not get redeclared.

      #ifndef I_ALREADY_DEFINED_THIS_STRUCT
      #define I_ALREADY_DEFINED_THIS_STRUCT
      typedef struct complextag
      {
      double dRe;
      double dIm;
      } COMPLEX;
      #endif


      CPUA 0x5041 Sonork 100.11743 Chicken Little "So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      1 Reply Last reply
      0
      • B boon kian

        Hi all, I have a vc problem which i am unable to think of a solution. so can anyone help ?? i have a data type as follow: typedef struct complextag { double dRe; double dIm; } COMPLEX; and i have 3 classes which need this data type. (main class, class A and class B). The main class will have to interact with class A and class B and pass a COMPLEX variable to them. Hence i have put the "typedef struct complextag" in the class A and class B header. I also include the class A and class B header in class main. However when i compile the program, vc complaint of this "error C2011: 'complextag': 'struct type redefinition' is there a way to solve this prob ?? or is there a way to make the COMPLEX data type to be universal like "int" or "float" ??? Thank you very much for the kind attention.

        S Offline
        S Offline
        Stephane Rodriguez
        wrote on last edited by
        #3

        Put the type definition in a header file (just in case), and add #pragma once at the top of it.

        1 Reply Last reply
        0
        • B boon kian

          Hi all, I have a vc problem which i am unable to think of a solution. so can anyone help ?? i have a data type as follow: typedef struct complextag { double dRe; double dIm; } COMPLEX; and i have 3 classes which need this data type. (main class, class A and class B). The main class will have to interact with class A and class B and pass a COMPLEX variable to them. Hence i have put the "typedef struct complextag" in the class A and class B header. I also include the class A and class B header in class main. However when i compile the program, vc complaint of this "error C2011: 'complextag': 'struct type redefinition' is there a way to solve this prob ?? or is there a way to make the COMPLEX data type to be universal like "int" or "float" ??? Thank you very much for the kind attention.

          B Offline
          B Offline
          boon kian
          wrote on last edited by
          #4

          Hi PJ Arends and .S.Rod. Really thanx a lot for your help !! I have used the suggested macro and it works !!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups