Answered Questions

  • C Pointer Size

    If p is declared as char *p then what is size of(*P)?

    vaishali

    • Feb 28th, 2012

    Size of *p is 1 byte, as it is character pointer.

    Divya

    • Jan 10th, 2012

    Array[0]

  • C/C++ black screen opens and closes

    While executing a program in C++, it happens the black screen opens and closes automatically without displaying the output(program is correct). How to recover from this situation?

    Amit

    • Jun 27th, 2014

    Use getchar() before return in the main.

    sebius

    • Aug 25th, 2013

    Try this

    Code
    1. system("pause");

  • C++ without Header files

    How we can run our c++ program without header files?

    Eric Nantel

    • Apr 23rd, 2015

    Put everything in the only cpp containing main()

    harshit

    • Apr 14th, 2015

    We can run c++ program without using header files by making the definition of all the functions and keywords in the programs

  • Inheritance in C++

    While doing inheritance in C++, one thing that is not inherited is what?

    rohit suri

    • Sep 11th, 2014

    There are four things which r not inherited in c++
    1>Constructor
    2>Destructor
    3>Assignment operator
    4>copy constructor
    5>Friend function

    Johnny

    • Jan 6th, 2014

    Friend declarations.

  • Dead Code

    What is dead code? Explain in programmatic way?

  • Why C++ does not have Virtual Constructors?

    Star Read Best Answer

    Editorial / Best Answer

    chethanhb  

    • Member Since Feb-2010 | Feb 25th, 2010


    I am one of the person who has pricked my head in understanding the above question. Let me explain in my way...

    If you have virtual function or (let me take just "virtual" keyword as of now), it means that this member function can be redefined by derived class. When we have a virtual function in a class, it will have vtable (virtual table). This vtable will have the address of the virtual function which is defined in derived.
    Now the point is, how you invoke the virtual function which is defined in derived class with the help of object of the class?
    Once you create an object of class, vptr (virtual pointer) will be created. Which inturn will be pointing to the base address of the vtable. So now it is clear that you can invoke the virtual funtion of derived class only with an object that has created.
    Now coming to virtual constructor,
    If we make constructor as virtual in base, it means that it could be redefined in derived. Keep in mind that constructor is invoked during object creation (object is not created yet. still it is in the status "creating". Object will create only after executing constructor part code). Assume you are trying to create object of the class which has virtual constructor. During this process constructor of the class will be invoked. It looks for virtual keyword. Now it tries to look for virtual constructor in derived. But not possible bcz there is no vptr and no vtable avaibale at this point of time. So, when object is not created, then there is no vptr. If no vptr for this object, then how the consturtor of derived is invoked?. No address of this construtor will available in vtable.
    Hence there is no point in having virtual constructor.

    I believe that i have cleared your doubt.

    Venkataramakrishna

    • Mar 22nd, 2018

    Whenever a class object is created this pointer is created just before initializing class constructor member values. If the constructor is virtual, you cannot create this pointer.

    vikash tiwary

    • May 11th, 2017

    Virtual functions are used in order to invoke functions based on the type of object pointed by the pointer. But is not "invoked", it is called only once when it is declared. so, a constructor cannot be virtual.

  • Difference between a process and a program?

    venky

    • Jul 5th, 2016

    Program is machine code combined with data as a executable image, which is passive. If program is actively in running then its called process.

    Ashwini D M

    • May 13th, 2016

    The new process and the process representing execution of program have a many to one relationship with the program. This is called concurrent program. processes that coexist in the system at some time...

  • What is abstraction?

    Abstraction is of the process of hiding unwanted details from the user. 

    Ramya

    • May 31st, 2013

    Mechanism of exposing only the interface and hiding the implementation data from user.

    mukrram ur rahman

    • Dec 9th, 2012

    Abstraction exactly involve the process of involving relevant things while ignoring the irrelevant things.

  • If a method is declared as protected, where may the method be accessed

    A protected method may only be accessed by classes or interfaces of the same package orby subclasses of the class in which it is declared.