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. error C2027 ?

error C2027 ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++
8 Posts 5 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.
  • Z Offline
    Z Offline
    zon_cpp
    wrote on last edited by
    #1

    Hi! i define two structs in .h file:

    struct s1
    {
    CString str;
    struct s2* ss2;
    };
    struct s2
    {
    int i;
    CString name;
    };

    and in .cpp file, in a function i use of this structs:

    s1 myS;
    myS.str = "";
    myS.ss2->i = 0; // error C2027: use of undefined type s2

    please help me, how do i solve this error?

    Zo.Naderi-Iran

    _ Z 2 Replies Last reply
    0
    • Z zon_cpp

      Hi! i define two structs in .h file:

      struct s1
      {
      CString str;
      struct s2* ss2;
      };
      struct s2
      {
      int i;
      CString name;
      };

      and in .cpp file, in a function i use of this structs:

      s1 myS;
      myS.str = "";
      myS.ss2->i = 0; // error C2027: use of undefined type s2

      please help me, how do i solve this error?

      Zo.Naderi-Iran

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Put struct s2 before struct s1,

      struct s2
      {
      int i;
      CString name;
      };

      struct s1
      {
      CString str;
      struct s2* ss2;
      };

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      P 1 Reply Last reply
      0
      • Z zon_cpp

        Hi! i define two structs in .h file:

        struct s1
        {
        CString str;
        struct s2* ss2;
        };
        struct s2
        {
        int i;
        CString name;
        };

        and in .cpp file, in a function i use of this structs:

        s1 myS;
        myS.str = "";
        myS.ss2->i = 0; // error C2027: use of undefined type s2

        please help me, how do i solve this error?

        Zo.Naderi-Iran

        Z Offline
        Z Offline
        zon_cpp
        wrote on last edited by
        #3

        ohhhhhhhh, my problem was solved; the problem is in struct name. the struct name was incorrect in my code.

        struct s1
        {
        CString str;
        struct z2* ss2; // the correct struct name is s2
        };
        struct s2
        {
        int i;
        CString name;
        };

        and the error was : error C2027: use of undefined type z2 when i Write in code project, this code, i Pay attention this problem. thank you and excuse me,

        Zo.Naderi-Iran

        1 Reply Last reply
        0
        • _ _Superman_

          Put struct s2 before struct s1,

          struct s2
          {
          int i;
          CString name;
          };

          struct s1
          {
          CString str;
          struct s2* ss2;
          };

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          «_Superman_» wrote:

          Put struct s2 before struct s1,

          This won't make any difference.

          Software rusts. Simon Stephenson, ca 1994.

          L T 2 Replies Last reply
          0
          • P Peter_in_2780

            «_Superman_» wrote:

            Put struct s2 before struct s1,

            This won't make any difference.

            Software rusts. Simon Stephenson, ca 1994.

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

            Peter_in_2780 wrote:

            This won't make any difference.

            Try it.

            It's time for a new signature.

            P 1 Reply Last reply
            0
            • P Peter_in_2780

              «_Superman_» wrote:

              Put struct s2 before struct s1,

              This won't make any difference.

              Software rusts. Simon Stephenson, ca 1994.

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              SuperMan is right, there are two way to solve above problem apart from actual problem (Struct Name mismatch). 1. As Mentioned by Superman 2. Forward Declaration ! like this

              struct s2; //forward Declaration
              struct s1
              {
              CString str;
              struct s2* ss2;
              };

              struct s2
              {
              int i;
              CString name;
              };

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
              Never mind - my own stupidity is the source of every "problem" - Mixture

              cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

              1 Reply Last reply
              0
              • L Lost User

                Peter_in_2780 wrote:

                This won't make any difference.

                Try it.

                It's time for a new signature.

                P Offline
                P Offline
                Peter_in_2780
                wrote on last edited by
                #7

                Richard MacCutchan wrote:

                Try it.

                #include <iostream.h>
                struct a {
                int aa;
                struct b *pb;
                };
                struct b {
                int bb;
                struct a *pa;
                };

                #pragma argsused
                int main(int argc, char* argv[])
                {
                struct a *xa = new struct a;
                struct b *xb = new struct b;
                xa->pb = xb;
                xa->pb->bb = 5;
                cout << xb->bb;
                return 0;
                }

                compiles and runs in my world. OK, so I'm not (M$) politically correct - I'm currently using Borland Turbo C++. I vaguely remember K&R or Stroustrup talking about this kind of forward reference - a pointer is as big as a pointer, regardless of what it points to, so all the compiler has to do is accept the implicit declaration. btw, I don't want to get into a flame war about standards and compliance. :) [edit][rant]However, I do think the 1-votes are unwarranted. Note that the OP's problem was *never* with the struct definitions, but turned out to be a typo in later reference. Two of you jumped down my throat. Personally, I don't give a flying, but the youngsters watching this might get the wrong impression.[/rant][/edit]

                Software rusts. Simon Stephenson, ca 1994.

                modified on Tuesday, July 27, 2010 12:39 AM

                L 1 Reply Last reply
                0
                • P Peter_in_2780

                  Richard MacCutchan wrote:

                  Try it.

                  #include <iostream.h>
                  struct a {
                  int aa;
                  struct b *pb;
                  };
                  struct b {
                  int bb;
                  struct a *pa;
                  };

                  #pragma argsused
                  int main(int argc, char* argv[])
                  {
                  struct a *xa = new struct a;
                  struct b *xb = new struct b;
                  xa->pb = xb;
                  xa->pb->bb = 5;
                  cout << xb->bb;
                  return 0;
                  }

                  compiles and runs in my world. OK, so I'm not (M$) politically correct - I'm currently using Borland Turbo C++. I vaguely remember K&R or Stroustrup talking about this kind of forward reference - a pointer is as big as a pointer, regardless of what it points to, so all the compiler has to do is accept the implicit declaration. btw, I don't want to get into a flame war about standards and compliance. :) [edit][rant]However, I do think the 1-votes are unwarranted. Note that the OP's problem was *never* with the struct definitions, but turned out to be a typo in later reference. Two of you jumped down my throat. Personally, I don't give a flying, but the youngsters watching this might get the wrong impression.[/rant][/edit]

                  Software rusts. Simon Stephenson, ca 1994.

                  modified on Tuesday, July 27, 2010 12:39 AM

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

                  Well I did not jump down your throat, nor did I 1-vote you. I merely challenged your assertion that changing the order of the declarations would not make any difference. I do agree with you that we don't want to start a flame war with this.

                  It's time for a new signature.

                  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