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. what is differnce between both following

what is differnce between both following

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
6 Posts 5 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.
  • S Offline
    S Offline
    santhosh padamatinti
    wrote on last edited by
    #1

    I have one doubt please give me the answer. I read some where in C++, if we want to access base class constructor using derived class constructor like bellow is possible:

    class base
    {
    base()
    };

    class derived:public base
    

    {
    derived():base()
    {
    }
    };

    normally i used like bellow

    class base
    {
    base()
    {
    }
    };

    class derived:public base
    

    {
    derived()
    {
    }
    };

    My question is what is the difference between both approaches. In which cases I have to use first one and in which cases i have to use second one.

    To invent something, you need a mountain of junk in your mind. ---------------------Thomas alva edison

    G _ P A 4 Replies Last reply
    0
    • S santhosh padamatinti

      I have one doubt please give me the answer. I read some where in C++, if we want to access base class constructor using derived class constructor like bellow is possible:

      class base
      {
      base()
      };

      class derived:public base
      

      {
      derived():base()
      {
      }
      };

      normally i used like bellow

      class base
      {
      base()
      {
      }
      };

      class derived:public base
      

      {
      derived()
      {
      }
      };

      My question is what is the difference between both approaches. In which cases I have to use first one and in which cases i have to use second one.

      To invent something, you need a mountain of junk in your mind. ---------------------Thomas alva edison

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      I have a doubt about people who post the same question 3 minutes after they have asked it the first tiome !!! STOP IT BE PATIENT 'g'

      S 1 Reply Last reply
      0
      • G Garth J Lancaster

        I have a doubt about people who post the same question 3 minutes after they have asked it the first tiome !!! STOP IT BE PATIENT 'g'

        S Offline
        S Offline
        santhosh padamatinti
        wrote on last edited by
        #3

        sorry, And thanks for valuable reply. My internet connection is having problem. First time it given a message "not update your message". That's why i updated again. Any way sorry for inconvenience. I deleted first one.

        To invent something, you need a mountain of junk in your mind. ---------------------Thomas alva edison

        1 Reply Last reply
        0
        • S santhosh padamatinti

          I have one doubt please give me the answer. I read some where in C++, if we want to access base class constructor using derived class constructor like bellow is possible:

          class base
          {
          base()
          };

          class derived:public base
          

          {
          derived():base()
          {
          }
          };

          normally i used like bellow

          class base
          {
          base()
          {
          }
          };

          class derived:public base
          

          {
          derived()
          {
          }
          };

          My question is what is the difference between both approaches. In which cases I have to use first one and in which cases i have to use second one.

          To invent something, you need a mountain of junk in your mind. ---------------------Thomas alva edison

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          In this case there is no differnce. But consider this case.

          class base
          {
          base(int i)
          {
          }
          };

          class derived : public base
          {
          derived(int j) : base(j)
          {
          }
          };

          In the above case you have to explicitly call the base class constructor like this.

          «_Superman_» I love work. It gives me something to do between weekends.
          Microsoft MVP (Visual C++)

          1 Reply Last reply
          0
          • S santhosh padamatinti

            I have one doubt please give me the answer. I read some where in C++, if we want to access base class constructor using derived class constructor like bellow is possible:

            class base
            {
            base()
            };

            class derived:public base
            

            {
            derived():base()
            {
            }
            };

            normally i used like bellow

            class base
            {
            base()
            {
            }
            };

            class derived:public base
            

            {
            derived()
            {
            }
            };

            My question is what is the difference between both approaches. In which cases I have to use first one and in which cases i have to use second one.

            To invent something, you need a mountain of junk in your mind. ---------------------Thomas alva edison

            P Offline
            P Offline
            Peter Weyzen
            wrote on last edited by
            #5

            For the example you give -- they are the same. The compiler is able to figure it out -- as "base" has a default constructor... "base()" The easiest way to see what's up here is to write both examples and run it through the debugger.

            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer [SoonR Inc -- PC Power delivered to your phone](http://www.soonr.com)

            1 Reply Last reply
            0
            • S santhosh padamatinti

              I have one doubt please give me the answer. I read some where in C++, if we want to access base class constructor using derived class constructor like bellow is possible:

              class base
              {
              base()
              };

              class derived:public base
              

              {
              derived():base()
              {
              }
              };

              normally i used like bellow

              class base
              {
              base()
              {
              }
              };

              class derived:public base
              

              {
              derived()
              {
              }
              };

              My question is what is the difference between both approaches. In which cases I have to use first one and in which cases i have to use second one.

              To invent something, you need a mountain of junk in your mind. ---------------------Thomas alva edison

              A Offline
              A Offline
              Alexey Malyshev
              wrote on last edited by
              #6

              these both won't compile

              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