#include <iostream>
using namespace std;

class bike {
  public:
		bike ()
		{
			cout << "Bike: no parameters\n";
		}
		bike (int a)
		{
			cout << "Bike: int parameter\n";
		}
		void color(int a,int b)
		{
			cout<<"Inside Bike Color"<<endl;
		}
};

class ducati : public bike {
  public:
		ducati (int a)
		{
			cout << "Ducati: int parameter\n\n";
		}
		void color(int a,int b,int c)
		{
					cout<<"Inside Ducati Color"<<endl;
		}
	};

class honda : public bike {
  public:
	  honda (int a) : bike (a)
      {
    	cout << "honda: int parameter\n\n";
      }

};

int main ()
{
  ducati monster(0);
  ducati *dObj=new ducati(10);
  bike *bObj=&monster;
  bObj->color(10,20,30); //it's showing error at this line. 

  return 0;
}

Please help me out

void color(int a,int b)

Two parameters.

bObj->color(10,20,30);

Three arguments.

I see what you wanted to happen, but it won't work because ducati's version of color() is an overload rather than an override. When looking at the object through a pointer to bike, you can only see the public member functions declared in bike. Since the three parameter version of color() is added in ducati, it's not visible from a pointer to bike even if that pointer points to a ducati object.

You can achieve something similar with judicious constructor parameters, virtual member functions, and polymorphism:

#include <iostream>

using namespace std;

class bike
{
public:
    bike() {
        cout << "bike()\n";
    }
    bike(int a) {
        cout << "bike(int a)\n";
    }
    virtual void color(int a, int b) {
        cout<<"Inside Bike Color"<<endl;
    }
};

class ducati : public bike
{
public:
    ducati(int a): bike(a) {
        cout << "ducati(int a)\n";
    }
    ducati(int a, int c): bike(a) {
        cout << "ducati(int a, int c)\n";
    }
    virtual void color(int a, int b) {
        cout<<"Inside Ducati Color"<<endl;
    }
};

int main()
{
    ducati monster(0, 30);
    bike *bObj = &monster;
    
    bObj->color(10, 20);
}
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.