FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How do i access the constructors from a base class?





shashwatblack
Code:

#include <iostream>

using namespace std;

class bComplex
{
    protected:
    float Real, Imag;
    public:
    bComplex(float r, float i) : Real(r), Imag(i) {}
    void display()
    {
        cout << "(" << Real << ", " << Imag << ")" << endl;
    }
    float getReal() {return Real;}
    float getImag() {return Imag;}
};

class dComplex : public bComplex
{
    public:
    bComplex add(bComplex& var)
    {
        return bComplex(Real + var.getReal(), Imag + var.getImag());
    }
    friend class fComplex;
};

int main()
{
    bComplex base(5, 2);
    base.display();
    //dComplex derived(2, 3);            //This gives an error.
    //derived.add(base).display();
    return 0;
}



Also when i use
Code:
dComplex(float r, float i) : Real(r), Imag(i) {}

in the derived class, it says `Real` and `Imag` are not a member of `dComplex`
Peterssidan
You have to define the dComplex constructor to use the bComplex constructor.
Code:
dComplex(float r, float i) : bComplex(r, i) {}
Related topics
751 Useful Windows XP Files
Site Nav Suggestions...
Implementing your database access in PHP as a layer.
C++ Microsoft Access Database
Frankfurt Motor Show, 2005
The best mobile Phone
Fatal error: Cannot instantiate non-existent class:
Using databases
HOW TO CONNECT MY SITE TO AN ACCESS DATA BASE??
PHP VS ASP
c++
My Script
Trouble with Inheritance
Noobie's code
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.