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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Am i defining this struct wrong?

Am i defining this struct wrong?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
12 Posts 6 Posters 1 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.
  • L Lost User

    typedef struct _ID3Info
    {
    char Title[33];
    char Artist[33];
    char Album[33];
    char Year[5];
    char Genre;
    char Comment[33];
    } ID3Info, *pID3Info;

    when i define it that way Visual C++ compiler says: "error C2011: '_ID3Info' : 'struct' type redefinition" what am i doing wrong? Thanks

    M Offline
    M Offline
    Maxwell Chen
    wrote on last edited by
    #3

    I think what you wrote is correct. I used to code NI's drivers with many of such struct typedefs. And 3 minutes ago I copied your struct and pasted onto a console project and a MFC project, both of them compiled without an error! Maybe you post the entire build log, and we could find out what happened..... Maxwell Chen No code is good code.

    L 1 Reply Last reply
    0
    • M Maxwell Chen

      I think what you wrote is correct. I used to code NI's drivers with many of such struct typedefs. And 3 minutes ago I copied your struct and pasted onto a console project and a MFC project, both of them compiled without an error! Maybe you post the entire build log, and we could find out what happened..... Maxwell Chen No code is good code.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      Where is the entire build log located?

      M 1 Reply Last reply
      0
      • L Lost User

        Where is the entire build log located?

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #5

        You may rebuild all again, and copy the content in the Build tab of the Output window. Or you may copy what in the .plg file.... Maxwell Chen No code is good code.

        1 Reply Last reply
        0
        • L Lost User

          typedef struct _ID3Info
          {
          char Title[33];
          char Artist[33];
          char Album[33];
          char Year[5];
          char Genre;
          char Comment[33];
          } ID3Info, *pID3Info;

          when i define it that way Visual C++ compiler says: "error C2011: '_ID3Info' : 'struct' type redefinition" what am i doing wrong? Thanks

          N Offline
          N Offline
          Navin
          wrote on last edited by
          #6

          Anonymous wrote: when i define it that way Visual C++ compiler says: "error C2011: '_ID3Info' : 'struct' type redefinition" From the looks of it, it seems that _ID3Info is somehow aready defined. It could be that: 1. You have a struct of that name defined somewhere else 2. Perhaps you don't have "include guards" in the header file that defines the struct, and it is getting pulled in twice. I always do something like this to ensure that #2 does not happen: #ifndef _whatever_your_h_file_name_happens_to_be_ #define _whatever_your_h_file_name_happens_to_be_ (code of the include file goes here) #endif No generalization is 100% true. Not even this one.

          B 1 Reply Last reply
          0
          • R RockNix

            Delete the struct name in the first line : typedef struct { . . So far ... RockNix/// ------------------------------------ www.klangwerker.de Need some articles about Threading, Subclassing, Double Buffering ? Go for it ... Look out for free Win32 Serial Communication Module for VC++ or Borland C++ Builder Visit us on www.klangwerker.de ------------------------------------

            T Offline
            T Offline
            Tom Archer
            wrote on last edited by
            #7

            The name after the struct is a "tag". The posters problem is elsewhere. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

            1 Reply Last reply
            0
            • L Lost User

              typedef struct _ID3Info
              {
              char Title[33];
              char Artist[33];
              char Album[33];
              char Year[5];
              char Genre;
              char Comment[33];
              } ID3Info, *pID3Info;

              when i define it that way Visual C++ compiler says: "error C2011: '_ID3Info' : 'struct' type redefinition" what am i doing wrong? Thanks

              T Offline
              T Offline
              Tom Archer
              wrote on last edited by
              #8

              Like Navin, your struct compiles fine in my code. I think if you follow his advice you'll find the source of your problem. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

              1 Reply Last reply
              0
              • N Navin

                Anonymous wrote: when i define it that way Visual C++ compiler says: "error C2011: '_ID3Info' : 'struct' type redefinition" From the looks of it, it seems that _ID3Info is somehow aready defined. It could be that: 1. You have a struct of that name defined somewhere else 2. Perhaps you don't have "include guards" in the header file that defines the struct, and it is getting pulled in twice. I always do something like this to ensure that #2 does not happen: #ifndef _whatever_your_h_file_name_happens_to_be_ #define _whatever_your_h_file_name_happens_to_be_ (code of the include file goes here) #endif No generalization is 100% true. Not even this one.

                B Offline
                B Offline
                Brian Delahunty
                wrote on last edited by
                #9

                Navin wrote: #ifndef _whatever_your_h_file_name_happens_to_be_ #define _whatever_your_h_file_name_happens_to_be_ (code of the include file goes here) #endif You could also use:

                #pragma once

                instead of the above ... however the above woudl be the more standard way of doing things :-D


                :~ (-_-) :~

                N 1 Reply Last reply
                0
                • L Lost User

                  typedef struct _ID3Info
                  {
                  char Title[33];
                  char Artist[33];
                  char Album[33];
                  char Year[5];
                  char Genre;
                  char Comment[33];
                  } ID3Info, *pID3Info;

                  when i define it that way Visual C++ compiler says: "error C2011: '_ID3Info' : 'struct' type redefinition" what am i doing wrong? Thanks

                  B Offline
                  B Offline
                  Brian Delahunty
                  wrote on last edited by
                  #10

                  Navin wrote: #ifndef _whatever_your_h_file_name_happens_to_be_ #define _whatever_your_h_file_name_happens_to_be_ (code of the include file goes here) #endif You could also use:

                  #pragma once

                  instead of the above ... however the above woudl be the more standard way of doing things :-D


                  :~ (-_-) :~

                  1 Reply Last reply
                  0
                  • B Brian Delahunty

                    Navin wrote: #ifndef _whatever_your_h_file_name_happens_to_be_ #define _whatever_your_h_file_name_happens_to_be_ (code of the include file goes here) #endif You could also use:

                    #pragma once

                    instead of the above ... however the above woudl be the more standard way of doing things :-D


                    :~ (-_-) :~

                    N Offline
                    N Offline
                    Navin
                    wrote on last edited by
                    #11

                    Brian Delahunty wrote: #pragma once Yes, my way would be more "standard", but yours is prettier. :-D No generalization is 100% true. Not even this one.

                    B 1 Reply Last reply
                    0
                    • N Navin

                      Brian Delahunty wrote: #pragma once Yes, my way would be more "standard", but yours is prettier. :-D No generalization is 100% true. Not even this one.

                      B Offline
                      B Offline
                      Brian Delahunty
                      wrote on last edited by
                      #12

                      Navin wrote: Yes, my way would be more "standard", but yours is prettier. Thanks ;)


                      :~ (-_-) :~

                      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