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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. constructor related questions

constructor related questions

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorialcareer
3 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.
  • K Offline
    K Offline
    kumar_mk
    wrote on last edited by
    #1

    was asked in an interview ---> 1. If the default constructor fails what happens? 2. What is Conversion constructor? Please give a small code example. 3. Why there is no virtual constructor? thanx in advance kumar_windows

    R L 2 Replies Last reply
    0
    • K kumar_mk

      was asked in an interview ---> 1. If the default constructor fails what happens? 2. What is Conversion constructor? Please give a small code example. 3. Why there is no virtual constructor? thanx in advance kumar_windows

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      1. Fails? In what way? If an exception is thrown, it's the same as if any other exception is thrown. The object is left in an undefined state, and should not be used. 2. A constructor that can be used to convert between different types. It takes one argument, and allows you to typecast from the argument type to the class type. 3. Because when you create a class, the compiler has to know exactly what type it is. The virtual function pointer table is initialised as part of the constructor call, so there is no way to implement a virtual function lookup until after the constructor completes.

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      1 Reply Last reply
      0
      • K kumar_mk

        was asked in an interview ---> 1. If the default constructor fails what happens? 2. What is Conversion constructor? Please give a small code example. 3. Why there is no virtual constructor? thanx in advance kumar_windows

        L Offline
        L Offline
        Laxman Auti
        wrote on last edited by
        #3

        kumar_windows wrote:

        If the default constructor fails what happens?

        http://burks.bton.ac.uk/burks/language/cpp/cppfaq/exceptio.htm#[17.1][^]

        kumar_windows wrote:

        2. What is Conversion constructor? Please give a small code example.

        A constructor that accepts one argument of a different type For e.g

        CDemo d{
        int m_i;
        public:
        CDemo(int i){
        m_i=i;
        }
        };

        kumar_windows wrote:

        Why there is no virtual constructor?

        There is nothing like Virtual Constructor. The Constructor can’t be virtual as the constructor is a code which is responsible for creating a instance of a class and it can’t be delegated to any other object by virtual keyword means. Knock out 't' from can't, You can if you think you can :cool:

        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