Hi there I have the following problem!

Please help!

class Base {
   //private methods
       void printMyType() {
           cout << "this is base type" << endl;
       }

  //public methods
      void printAllInfo() {
           cout << "this An accout" << endl;
           printMyType();
      }

}; //end base class



class derived : public Base {

   //private method
     void printMyType() {
           cout << "this is derived type" << endl;
       }

   //public methods
    void printAllInfo() {
           obileAccount::PrintAccountInfo();
           printMyType();
      }
}; //end derived class

Ok i have the above methods! Its an assingment so the public and private methods visabilites cannot be altered.

Now when I call the printAllInfo() from the base class it prints out the following
"this An accout"
"this is base type""this An accout"

I want to write correct the printAllInfo() method in the derived class so that
when I call it it prints

"this An accout"
"this is a derived account"

so in other words when I call the printAllInfo method in derived class the printMyType() method overwirtes the one in the base class and prints "this is a derived account"

thanks

pls help

put [ code = cpp ]
and [ / code ] around your code plz.
without spaces inside the brackets of course

Before your public methods you always have to add public: as in your posted code all the methods are private (If you don't define access specifiers in a class, all the data is standard private) ...

well in class the data members and functions are taken in as private by default by the compiler itself , unless u explicit mention that.

well my suggestion is why don't you do a virtual function?

well my suggestion is why don't you do a virtual function?

To code take above is to be take to literally ! I have a header file which defines all the visabilities so thats all taken care of! please can someone advise me on the idea of how I get the overiding printAccountType() method to work?

thanks

As far as i know methods that are private cannot be virtual since they can only be used by the same class anyway.

Before your public methods you always have to add public: as in your posted code all the methods are private (If you don't define access specifiers in a class, all the data is standard private) ...

The code take above is to be take to literally ! I have a header file which defines all the visabilities so thats all taken care of! please can someone advise me on the idea of how I get the overiding printAccountType() method to work?

thanks

As far as i know methods that are private cannot be virtual since they can only be used by the same class anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.