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. CPP Syntax

CPP Syntax

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutoriallounge
4 Posts 3 Posters 1 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
    Bram van Kampen
    wrote on last edited by
    #1

    Hi, I have a Class, which contains as member another class. This latter contained class has no default constructor, but requires a Parameter in it's constructor. How do I call this latter constructor in the constructor of the first class. This is a General CPP Question, but it is a bit abstract, so I give a Concrete example: For instance: I have a class derived from CDialog. It contains four instances of a custom class CDragBar. The CDragBar class in it's constructor determines whether it is horizontal or vertical. (one cannot have an indeterminate one) In this case I know ways around this conundrum,(e.g. Provide a default constructor for the CDragBar class, and provide methods like SetVertical() and SetHorizontal(), to be called in the 'CDialog derived classes constructor') but wonder is there a CPP syntax that could be used instead. The example I gave is in a way quite trivial. The Colon separated Constructor List only works for base class constructors of the main classes constructor in Microsoft Compilers, and not for contained member classes. Anyone any ideas? Even if the idea is that no such syntax exists. Kind Regards,

    Bram van Kampen

    CPalliniC 1 Reply Last reply
    0
    • B Bram van Kampen

      Hi, I have a Class, which contains as member another class. This latter contained class has no default constructor, but requires a Parameter in it's constructor. How do I call this latter constructor in the constructor of the first class. This is a General CPP Question, but it is a bit abstract, so I give a Concrete example: For instance: I have a class derived from CDialog. It contains four instances of a custom class CDragBar. The CDragBar class in it's constructor determines whether it is horizontal or vertical. (one cannot have an indeterminate one) In this case I know ways around this conundrum,(e.g. Provide a default constructor for the CDragBar class, and provide methods like SetVertical() and SetHorizontal(), to be called in the 'CDialog derived classes constructor') but wonder is there a CPP syntax that could be used instead. The example I gave is in a way quite trivial. The Colon separated Constructor List only works for base class constructors of the main classes constructor in Microsoft Compilers, and not for contained member classes. Anyone any ideas? Even if the idea is that no such syntax exists. Kind Regards,

      Bram van Kampen

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

      Do you mean something like

      #include using namespace std;

      class A
      {
      int _i;
      public:
      A(int i):_i(i){}
      int get() const {return _i;}
      };

      class B
      {
      A _a;

      public:
      B():_a(10){}
      B(int i):_a(i){}

      const A & get(){ return _a;}
      };

      int main()
      {
      B b0;
      B b1(1);
      cout << b0.get().get() << ", " << b1.get().get() << endl;
      }

      In testa che avete, signor di Ceprano?

      U B 2 Replies Last reply
      0
      • CPalliniC CPallini

        Do you mean something like

        #include using namespace std;

        class A
        {
        int _i;
        public:
        A(int i):_i(i){}
        int get() const {return _i;}
        };

        class B
        {
        A _a;

        public:
        B():_a(10){}
        B(int i):_a(i){}

        const A & get(){ return _a;}
        };

        int main()
        {
        B b0;
        B b1(1);
        cout << b0.get().get() << ", " << b1.get().get() << endl;
        }

        U Offline
        U Offline
        User 13406711
        wrote on last edited by
        #3

        Nice, I think you need to try this source: Selection, Insertion, Bubble and Heap Sort in C++ | Codinglio[^] :) :)

        1 Reply Last reply
        0
        • CPalliniC CPallini

          Do you mean something like

          #include using namespace std;

          class A
          {
          int _i;
          public:
          A(int i):_i(i){}
          int get() const {return _i;}
          };

          class B
          {
          A _a;

          public:
          B():_a(10){}
          B(int i):_a(i){}

          const A & get(){ return _a;}
          };

          int main()
          {
          B b0;
          B b1(1);
          cout << b0.get().get() << ", " << b1.get().get() << endl;
          }

          B Offline
          B Offline
          Bram van Kampen
          wrote on last edited by
          #4

          Well, The issue is very similar to that example. I note the curly braces and the absence of a terminating semi colon. What is the reasoning behind the syntax. Does that syntax intentionally leave out the terminating semi colon, or, is that an oversight? Going to try that! Thanks and Regards :)

          Bram van Kampen

          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