#include<iostream>
class base
{
int m_data;
public:
base(const int data):m_data(data){}
base(const base& cpy):m_data(cpy.m_data){}
base& operator=(const int rhs){m_data=rhs;return(*this);}
base& operator=(const base& rhs){m_data=rhs.m_data;return(*this);}
virtual ~base(){}
};
class derived
{
public:
derived(const int data):base(data){}
derived(const derived& cpy):base(cpy){}
derived& operator=(const int rhs){return(base::operator=(rhs));}
derived& operator=(const derived& rhs){return(base::operator=(rhs));}
virtual ~derived(){}
};
int main()
{
derived d=42;
}
Chat with our AI personalities
what is the pure algorithm instead of cpp program?
Such a program is called a Quine. http://en.wikipedia.org/wiki/Quine_(computing)
Use the scope resolution operator (::) to explicitly call the base class method. Note that the base class method must be protected or public in order for a derived class to access it. Private members are only accessible to the class itself and to friends of the class, regardless of whether the derivative uses public, protected or private inheritance. It is quite normal for a base class to provide a "default" implementation for a virtual method for which a derived class may override. Although the derived class will generally provide its own implementation of the method, it may also call the base class method either before, during or after performing its own implementation. The following shows minimal class declarations demonstrating a call to a protected base class method from a derived class override. class base { protected: // accessible to all instances of this class, its friends and its derivatives. virtual void method(){ /* do something */ } }; class derived : public base { public: // full-accessible outside of class. virtual void method(){ /* do something (or do nothing) */ base::method(); // call base class method. /* do something else (or do nothing) */ } };
The .cpp extension is merely conventional; it is not required by the C++ standard. You can actually use any file extension you wish.
int main (void) { puts ("charminar"); return 0; }