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. Problem declaring data type

Problem declaring data type

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
7 Posts 4 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.
  • M Offline
    M Offline
    marca292
    wrote on last edited by
    #1

    Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?

    #ifndef COMMONSETTINGS_H_
    #define COMMONSETTINGS_H_

    typedef enum
    {
        XX = 0,
        YY,
        ZZ
    } ProductType;
    

    #endif /* COMMONSETTINGS_H_ */

    And the class that uses the type ProductType

    class TestClass
    {
    public:
    //! Constructor
    TestClass();

    //! Desctructor
    virtual ~TestClass();
    

    private:
    ProductType product;
    };

    How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof

    J L S 3 Replies Last reply
    0
    • M marca292

      Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?

      #ifndef COMMONSETTINGS_H_
      #define COMMONSETTINGS_H_

      typedef enum
      {
          XX = 0,
          YY,
          ZZ
      } ProductType;
      

      #endif /* COMMONSETTINGS_H_ */

      And the class that uses the type ProductType

      class TestClass
      {
      public:
      //! Constructor
      TestClass();

      //! Desctructor
      virtual ~TestClass();
      

      private:
      ProductType product;
      };

      How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof

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

      Stupid question, but did you #include the header file in your compilation unit?

      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

      M 1 Reply Last reply
      0
      • M marca292

        Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?

        #ifndef COMMONSETTINGS_H_
        #define COMMONSETTINGS_H_

        typedef enum
        {
            XX = 0,
            YY,
            ZZ
        } ProductType;
        

        #endif /* COMMONSETTINGS_H_ */

        And the class that uses the type ProductType

        class TestClass
        {
        public:
        //! Constructor
        TestClass();

        //! Desctructor
        virtual ~TestClass();
        

        private:
        ProductType product;
        };

        How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        Enumerations did not need the typedef keyword. Use

        enum ProductType
        {
        XX,
        YY,
        ZZ
        };

        You should also think about moving your common settings into those classes they are belonging to (e.g. the class that acts according to the ProductType enumeration). This is better C++ style and makes your code modules better portable to other projects. To use such class specific enumerations from other classes, prefix them with the class name (e.g. MyClass::ProductType). Joe

        M 1 Reply Last reply
        0
        • M marca292

          Hi, I'm working with a C++ project and have created a new .h file that contains typedef of new types. How do I use the new types in another class?

          #ifndef COMMONSETTINGS_H_
          #define COMMONSETTINGS_H_

          typedef enum
          {
              XX = 0,
              YY,
              ZZ
          } ProductType;
          

          #endif /* COMMONSETTINGS_H_ */

          And the class that uses the type ProductType

          class TestClass
          {
          public:
          //! Constructor
          TestClass();

          //! Desctructor
          virtual ~TestClass();
          

          private:
          ProductType product;
          };

          How do I do to use ProductTyp in TestClass? Now I get compile erro since TestClass can not find ProductType. What is the best way to solve this? I want to declare new types in a file and use the types in several other classes. /Olof

          S Offline
          S Offline
          S p k 521
          wrote on last edited by
          #4

          please include that headerfile..

          M 1 Reply Last reply
          0
          • S S p k 521

            please include that headerfile..

            M Offline
            M Offline
            marca292
            wrote on last edited by
            #5

            I already include that header file

            1 Reply Last reply
            0
            • L Lost User

              Stupid question, but did you #include the header file in your compilation unit?

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

              M Offline
              M Offline
              marca292
              wrote on last edited by
              #6

              Yes.

              1 Reply Last reply
              0
              • J Jochen Arndt

                Enumerations did not need the typedef keyword. Use

                enum ProductType
                {
                XX,
                YY,
                ZZ
                };

                You should also think about moving your common settings into those classes they are belonging to (e.g. the class that acts according to the ProductType enumeration). This is better C++ style and makes your code modules better portable to other projects. To use such class specific enumerations from other classes, prefix them with the class name (e.g. MyClass::ProductType). Joe

                M Offline
                M Offline
                marca292
                wrote on last edited by
                #7

                I use this solution, then it's working.

                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