CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Threaded View

  1. #1
    Join Date
    Jun 2008
    Location
    greater Cincinnati
    Posts
    54

    [RESOLVED] How do you declare a class within itself?

    Hello and good day.

    IDE: code::blocks
    OS: Windows 7



    I am a novice C++ programmer, and I am having trouble declaring a class withing itself or actually a vector of a class within itself.
    I am not sure on how to go about doing it or what alternatives I have. Whenever I add the " std::vector<COrderPreferences>
    orderPreferences; " to my CDomain class I get 1 very big error in stl_algobase.h - or I can comment out "std::vector<CDomain> domain;"
    , and leave the COrderPreferences vector and everything works.




    So below is a sample of my problem, could someone show me what is wrong, and give me some advice?





    Code:
    //-----------Domain.h
     
    #ifndef CDOMAIN_H
    #define CDOMAIN_H
    #include <vector>
     
     
     
     
    class CDomain
    {
        public:
     
            std::vector<COrderPreferences> orderPreferences;
            std::vector<CDomain> domain;
            void create();
    
    };
     
    #endif // CDOMAIN_H
    
     
     
    
     
    //---------CDomain.cpp
     
    #include "CDomain.h"
     
    void CDomain::create()
    {
         domain.resize(3);
    
    }
    
     
     
    
    
    //EDITED in respect to post #6 VicotorN
    
    
    
    
    
    
    
    
    
    
    //-------------COrderPreferences.h
    
    
    #ifndef CORDERPREFERENCES_H
    #define CORDERPREFERENCES_H
    
    #include <vector>
    #include <string>
    
    
    class COrderPreferences
    {
        public:
    
             struct ControlAttributes
            {
                   DWORD exStyles;
                   std::string types;
                   std::string defaultCaption;
                   DWORD styles;
                   int XStart;
                   int YStart;
                   int XWidth;
                   int YHeight;
    
    
    
                   ControlAttributes& operator=(ControlAttributes& a)
                   {
    
    //                   if  (this != &a) // protect against invalid self-assignment
    //                   {
                           exStyles       =    a.exStyles;
                           types          =    a.types;
                           defaultCaption =    a.defaultCaption;
                           styles         =    a.styles;
                           XStart         =    a.XStart;
                           YStart         =    a.YStart;
                           XWidth         =    a.XWidth;
                           YHeight        =    a.YHeight;
    
    
    //                   }
    
                       return *this;
                   }
            };
          
      
    
            ControlAttributes controlAttributes[15];
    };
    
    
    #endif // CORDERPREFERENCES_H



    Thank you very much for your time and effort. Best of wishes to everyone in this forum!
    Last edited by kmkkra; August 2nd, 2011 at 12:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured