What will be the output of the following C++ code? [code] #include <iostream> using namespace std; class Base {

Nguyễn Tân

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    class Base
    {
        public:
            Base(){}
            ~Base(){}
            protected:
            private: 
    };
    class Derived:public Base
    {
        public:
            Derived(){}
            Derived(){}
            private:
            protected:
    };
    int main()
    {
        cout << "The program exceuted" << endl;
    }
A. The program executed
B. Error
C. Runtime error
D. program exceuted
 
Answer: b
Explanation: We are allowed to overload constructor but in this case as both the constructor have no parameters which implies that both the constructor have same signature which is not allowed i.e. constructors can be overloaded but two overloaded constructors can not have same function signature.
 

Tìm kiếm

Back
Top