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. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C / C++ / MFC
11 Posts 7 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.
  • P Offline
    P Offline
    ppatel567
    wrote on last edited by
    #1

    [Message Deleted]

    G N S T R 5 Replies Last reply
    0
    • P ppatel567

      [Message Deleted]

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      ppatel567 wrote:

      Here why not only header files for CMyApp and CMySpec are not added. Why such kind of syntax?

      They are called Forward Declarations. The header files for these classes will be included in the CPP file.


      Nibu thomas Software Developer Faqs by Michael dunn

      1 Reply Last reply
      0
      • P ppatel567

        [Message Deleted]

        G Offline
        G Offline
        grigsoft
        wrote on last edited by
        #3

        It is not always possible to include header with desired declaration, in some cases you just don't want class CPatel to heaviliy depend on CMyApp. In such cases (and if CMyApp only encounters in CMyApp* form) it is easier to make such preliminary declaration. Igor Green http://www.grigsoft.com/ - files and folders comparison tools

        P 1 Reply Last reply
        0
        • G grigsoft

          It is not always possible to include header with desired declaration, in some cases you just don't want class CPatel to heaviliy depend on CMyApp. In such cases (and if CMyApp only encounters in CMyApp* form) it is easier to make such preliminary declaration. Igor Green http://www.grigsoft.com/ - files and folders comparison tools

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

          [Message Deleted]

          G M 2 Replies Last reply
          0
          • P ppatel567

            [Message Deleted]

            G Offline
            G Offline
            grigsoft
            wrote on last edited by
            #5

            Well, you don't have to use it anyway :) In most cases it can be avoided. Igor Green http://www.grigsoft.com/ - files and folders comparison tools

            S 1 Reply Last reply
            0
            • P ppatel567

              [Message Deleted]

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

              It takes years of experience for you to understand what grigsoft said. You will learn it from coding larger-scaled programs.


              Maxwell Chen

              1 Reply Last reply
              0
              • G grigsoft

                Well, you don't have to use it anyway :) In most cases it can be avoided. Igor Green http://www.grigsoft.com/ - files and folders comparison tools

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                Why would you want to avoid it? Minimizing dependencies in a header files is a good thing. Steve

                M 1 Reply Last reply
                0
                • S Stephen Hewitt

                  Why would you want to avoid it? Minimizing dependencies in a header files is a good thing. Steve

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

                  Stephen Hewitt wrote:

                  Minimizing dependencies in a header files is a good thing.

                  I second Steve's opinion!


                  Maxwell Chen

                  1 Reply Last reply
                  0
                  • P ppatel567

                    [Message Deleted]

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #9

                    This is called a Forward Declaration. The class CPpatel no doubt uses the services of the classes CMyApp and CMySpec and as such will have members that refer to them. If CPpatel has a member variable of, for example, the CMySpec class then you need to #include its header as the compiler needs to know its size to define CPpatel. For example: class CPpatel { .. .. ..     CMySpec m_TheSpec; // Header must be included. }; If, on the other hand, the CPpatel class contains a pointer or reference to the CMySpec class then the compiler doesn't need to know the object's size as all pointers/references to a class are the same size. In this case you can use a Forward Declaration and you don't need to #include its header. For example: class CPpatel { .. .. ..     CMySpec *m_pTheSpec; // Only Forward Declaration needed. }; This is a good thing as it minimises the dependencies of the header file and thus increases the stability of the project (in terms of maintenance) and decreases compile times. Sometimes Forward Declarations are used to break cyclic dependencies but I'll not go into that at this stage. Steve

                    1 Reply Last reply
                    0
                    • P ppatel567

                      [Message Deleted]

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

                      ppatel567 wrote:

                      I sometimes noticed that in the header file its only written asanyheader.h=======class CMyApp;class CMySpec;

                      thats we call forward decalaration of class

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      cheers, Alok Gupta VC Forum Q&A :- I/ IV

                      1 Reply Last reply
                      0
                      • P ppatel567

                        [Message Deleted]

                        R Offline
                        R Offline
                        Russell
                        wrote on last edited by
                        #11

                        This kind of declaration is used to help the compiler to understand what string used into the code are sintax errors or objects that are somewhere defined. I'll try to find a way to explain this to you with two examples,... and remember that the compiler will read the code in the same way of you, i.e. from top to bottom: First case: the error! class classA{ classB b; //The compiler tells: _What is **classB**? I don't know this.:(... => Error_ } class classB{ //Compiler interrupted:(, this isn't readed! ... } Second case: OK class classB; //You are telling to the compiler: _wait a moment, the definition of this class will came later_ class classA{ classB b; //The compiler tells: _What is **classB**? I don't know **how it is build**, but I know that it **exist** and it isn't a sintax error. So I can continue!_ } //The compiler tells: _Yahoooo:-D, now I will know what **classB** is!!_ class classB{ ... } Hope be clear

                        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