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. need help

need help

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelplearning
6 Posts 3 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.
  • E Offline
    E Offline
    Ehsan_MF
    wrote on last edited by
    #1

    Class A { A() //Constructor } class B: public A { B(...):A(...) {...} . . . } Any body know what is instruction "B(...):A(...)" in class B doing ?

    Beginner

    T C 2 Replies Last reply
    0
    • E Ehsan_MF

      Class A { A() //Constructor } class B: public A { B(...):A(...) {...} . . . } Any body know what is instruction "B(...):A(...)" in class B doing ?

      Beginner

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2
      1. you'll have to speak a better english if you want people here to understand you. 2) when providing a code sample, place it between <pre></pre> html tags so that it will be well formatted. 3) a function with the same name as a class is called a constructor. it's purpose is to initalize its members. you should really consider buying a C++ book and learn about object oriented programming...

      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      1 Reply Last reply
      0
      • E Ehsan_MF

        Class A { A() //Constructor } class B: public A { B(...):A(...) {...} . . . } Any body know what is instruction "B(...):A(...)" in class B doing ?

        Beginner

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        Yes, in the constructor of B, you call the constructor of A. It is usefull for example when you need to pass arguments to the constructor of A.


        Cédric Moonen Software developer
        Charting control [v1.2]

        E 1 Reply Last reply
        0
        • C Cedric Moonen

          Yes, in the constructor of B, you call the constructor of A. It is usefull for example when you need to pass arguments to the constructor of A.


          Cédric Moonen Software developer
          Charting control [v1.2]

          E Offline
          E Offline
          Ehsan_MF
          wrote on last edited by
          #4

          What is difference between

          B(...):A(...)
          {
          .
          .
          .
          }

          and

          B(...)
          {
          A(..);
          .
          .
          .
          }

          Beginner

          C 1 Reply Last reply
          0
          • E Ehsan_MF

            What is difference between

            B(...):A(...)
            {
            .
            .
            .
            }

            and

            B(...)
            {
            A(..);
            .
            .
            .
            }

            Beginner

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            The second syntax is invalid: the base class (A) needs to be constructed before your child class (B). So the only way to do that is to put it in the constructor initialisation list.


            Cédric Moonen Software developer
            Charting control [v1.2]

            E 1 Reply Last reply
            0
            • C Cedric Moonen

              The second syntax is invalid: the base class (A) needs to be constructed before your child class (B). So the only way to do that is to put it in the constructor initialisation list.


              Cédric Moonen Software developer
              Charting control [v1.2]

              E Offline
              E Offline
              Ehsan_MF
              wrote on last edited by
              #6

              thank you

              Beginner

              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