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. How to forward delare CArray class ?

How to forward delare CArray class ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 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.
  • V Offline
    V Offline
    VCSharp007
    wrote on last edited by
    #1

    Hi All, I have a requirement to add a CArray member varibale in my class without including afxtempl.h in my class header file. Is there any method to forward delare CArray class? Thankx in advance.

    C N K 3 Replies Last reply
    0
    • V VCSharp007

      Hi All, I have a requirement to add a CArray member varibale in my class without including afxtempl.h in my class header file. Is there any method to forward delare CArray class? Thankx in advance.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      VCSharp007 wrote:

      I have a requirement to add a CArray member varibale in my class without including afxtempl.h in my class header file

      IMHO you cannot satisfy the above requirement. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      1 Reply Last reply
      0
      • V VCSharp007

        Hi All, I have a requirement to add a CArray member varibale in my class without including afxtempl.h in my class header file. Is there any method to forward delare CArray class? Thankx in advance.

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

        VCSharp007 wrote:

        I have a requirement to add a CArray member varibale in my class without including afxtempl.h in my class header file.

        // Forward declare CArray.
        template<class TYPE, class ARG_TYPE> class CArray;

        class SomeClass
        {
        public:
        // No need to include afxtempl.h
        CArray<float, float>* pFloatArray = 0;
        };


        Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com

        V 1 Reply Last reply
        0
        • V VCSharp007

          Hi All, I have a requirement to add a CArray member varibale in my class without including afxtempl.h in my class header file. Is there any method to forward delare CArray class? Thankx in advance.

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #4

          This is a bad requirement, because than is the dependency unclear.:suss: Remember: Write selfexplaining code, so you dont need to document the code. You can also include the afxtempl.h in another header. stdafx.h is a good place because, the afxtempl.h wont be change a lot of times.

          Greetings from Germany

          1 Reply Last reply
          0
          • N Nibu babu thomas

            VCSharp007 wrote:

            I have a requirement to add a CArray member varibale in my class without including afxtempl.h in my class header file.

            // Forward declare CArray.
            template<class TYPE, class ARG_TYPE> class CArray;

            class SomeClass
            {
            public:
            // No need to include afxtempl.h
            CArray<float, float>* pFloatArray = 0;
            };


            Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com

            V Offline
            V Offline
            VCSharp007
            wrote on last edited by
            #5

            Thanks Nibu. But I have to use CArray varibale not pointer!!!!

            N 1 Reply Last reply
            0
            • V VCSharp007

              Thanks Nibu. But I have to use CArray varibale not pointer!!!!

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

              VCSharp007 wrote:

              But I have to use CArray varibale not pointer!!!!

              No then forward declaration won't work, since classes should know their sizes. Pointer is ok since size will be sizeof a pointer. Forward declaration just tells the compiler that the class is ok and definition of that is readily available somewhere. So it searches for the given class when code for the parent class is being generated. Otherwise include "afxtempl.h" in precompiler header file. But then again there will be issues when this header file is being used somewhere else where there is no precompiled header file.


              Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com

              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