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. Any solution to class redefinition

Any solution to class redefinition

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhelpquestion
13 Posts 5 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 Anyone have a solution for class redefinition ?? I have a based class and 2 derived class. When i try to write a main function using both the derived class i have a class redefinition problem. Can anyone guide me on how to solve the prob ?? Thanx a lot !!! bk

    A 1 Reply Last reply
    0
    • B boon kian

      Hi Anyone have a solution for class redefinition ?? I have a based class and 2 derived class. When i try to write a main function using both the derived class i have a class redefinition problem. Can anyone guide me on how to solve the prob ?? Thanx a lot !!! bk

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Its not very clear what you mean, maybe you can give an example of what you are trying to do?

      B 1 Reply Last reply
      0
      • A Anonymous

        Its not very clear what you mean, maybe you can give an example of what you are trying to do?

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

        eg: base class : class Employee { } derived class 1: class Temp:public Employee { } derived class 2: class Perm:public Employee { } main: #include "Perm.h" #include "Temp.h" <- this is where the redefinition occur due to 2 copy of "Employee.h" void main (void) { Temp a; Perm b; ...... } so beside changing the structure any solution to solve this prob ?? thanx a lot !! bk

        J 2 Replies Last reply
        0
        • B boon kian

          eg: base class : class Employee { } derived class 1: class Temp:public Employee { } derived class 2: class Perm:public Employee { } main: #include "Perm.h" #include "Temp.h" <- this is where the redefinition occur due to 2 copy of "Employee.h" void main (void) { Temp a; Perm b; ...... } so beside changing the structure any solution to solve this prob ?? thanx a lot !! bk

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          You need to protect the header file from multiple inclusions. A portable way is to do something like this:

          #ifndef __FILE_H__
          #define __FILE_H__

          // Header file contents here

          #endif // __FILE_H__

          If you are not worried about portability and is using VS.NET, you can write something like this:

          #pragma once
          // Header file contents here

          -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

          S B 2 Replies Last reply
          0
          • B boon kian

            eg: base class : class Employee { } derived class 1: class Temp:public Employee { } derived class 2: class Perm:public Employee { } main: #include "Perm.h" #include "Temp.h" <- this is where the redefinition occur due to 2 copy of "Employee.h" void main (void) { Temp a; Perm b; ...... } so beside changing the structure any solution to solve this prob ?? thanx a lot !! bk

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #5

            Oh yeah, i forgot to mention that the define at the top of each header file should be unique for each header file. I usually use this pattern: If the file is called file.h, the define symbol becomes __FILE_H__ So, if I had Employee.h, I'd define the symbol as __EMPLOYEE_H__ :) -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

            1 Reply Last reply
            0
            • J Jorgen Sigvardsson

              You need to protect the header file from multiple inclusions. A portable way is to do something like this:

              #ifndef __FILE_H__
              #define __FILE_H__

              // Header file contents here

              #endif // __FILE_H__

              If you are not worried about portability and is using VS.NET, you can write something like this:

              #pragma once
              // Header file contents here

              -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

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

              #pragma once huh?

              J 1 Reply Last reply
              0
              • S Stephane Rodriguez

                #pragma once huh?

                J Offline
                J Offline
                Jorgen Sigvardsson
                wrote on last edited by
                #7

                It automatically protects header files. A VS.NET extension which IMHO should be incorporated into C/C++. Idiot proof protection! :-D -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

                S R 2 Replies Last reply
                0
                • J Jorgen Sigvardsson

                  It automatically protects header files. A VS.NET extension which IMHO should be incorporated into C/C++. Idiot proof protection! :-D -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

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

                  me leaving the class room looking down my shoes. ;) [edit]#pragma once is not a VS.NET extension.[/edit]

                  J 1 Reply Last reply
                  0
                  • S Stephane Rodriguez

                    me leaving the class room looking down my shoes. ;) [edit]#pragma once is not a VS.NET extension.[/edit]

                    J Offline
                    J Offline
                    Jorgen Sigvardsson
                    wrote on last edited by
                    #9

                    .S.Rod. wrote: [edit]#pragma once is not a VS.NET extension.[/edit] Did it appear earlier? I assumed it was first included in VS.NET because VS.NET was the first environment where I noticed that the wizards generate code containing #pragma once. Speaking of extensions, do you know by any chance if you can force folding points in C++ source files using some [un]documented trick? #region is what I want, but that seems to be a C# only feature. -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

                    S 1 Reply Last reply
                    0
                    • J Jorgen Sigvardsson

                      .S.Rod. wrote: [edit]#pragma once is not a VS.NET extension.[/edit] Did it appear earlier? I assumed it was first included in VS.NET because VS.NET was the first environment where I noticed that the wizards generate code containing #pragma once. Speaking of extensions, do you know by any chance if you can force folding points in C++ source files using some [un]documented trick? #region is what I want, but that seems to be a C# only feature. -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

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

                      Jörgen Sigvardsson wrote: Did it appear earlier? I assumed it was first included in VS.NET because VS.NET was the first environment where I noticed that the wizards generate code containing #pragma once. As far as I can tell it was already available with MSDEV 97. Jörgen Sigvardsson wrote: Speaking of extensions, do you know by any chance if you can force folding points in C++ source files using some [un]documented trick? #region is what I want, but that seems to be a C# only feature. There is no way to force outlining. But the context menu shows a way to play with outlines regardless of the language you are using (they are saved in the .suo file, like bookmarks and other stuff). More info here[^].

                      J 1 Reply Last reply
                      0
                      • S Stephane Rodriguez

                        Jörgen Sigvardsson wrote: Did it appear earlier? I assumed it was first included in VS.NET because VS.NET was the first environment where I noticed that the wizards generate code containing #pragma once. As far as I can tell it was already available with MSDEV 97. Jörgen Sigvardsson wrote: Speaking of extensions, do you know by any chance if you can force folding points in C++ source files using some [un]documented trick? #region is what I want, but that seems to be a C# only feature. There is no way to force outlining. But the context menu shows a way to play with outlines regardless of the language you are using (they are saved in the .suo file, like bookmarks and other stuff). More info here[^].

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #11

                        .S.Rod. wrote: But the context menu shows a way to play with outlines regardless of the language you are using (they are saved in the .suo file, like bookmarks and other stuff). Yeah, I knew about that one. However, the .suo file is nothing I want to keep in CVS. The main reason I wanted to add the regions was to promote readability (hiding all the private stuff as much as possible which is of no interest anyway for the user of the class) and have it inlined in the code. Oh well, I guess I can't have everything. :) -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

                        1 Reply Last reply
                        0
                        • J Jorgen Sigvardsson

                          You need to protect the header file from multiple inclusions. A portable way is to do something like this:

                          #ifndef __FILE_H__
                          #define __FILE_H__

                          // Header file contents here

                          #endif // __FILE_H__

                          If you are not worried about portability and is using VS.NET, you can write something like this:

                          #pragma once
                          // Header file contents here

                          -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

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

                          Hi , Really thanx a lot for the help !!! bk

                          1 Reply Last reply
                          0
                          • J Jorgen Sigvardsson

                            It automatically protects header files. A VS.NET extension which IMHO should be incorporated into C/C++. Idiot proof protection! :-D -- Shine, enlighten me - shine Shine, awaken me - shine Shine for all your suffering - shine

                            R Offline
                            R Offline
                            Reservoir Dog
                            wrote on last edited by
                            #13

                            It's not really a VS.NET extension coz i've used #pragma once in VC++ 6 also. Though not sure if it was present in earlier versions too or not. And you will know my name is the Lord when I lay my vengeance upon thee.

                            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