#include <iostream>
#include<string>
using namespace std;

class Book
{

	private:

		string title;

		double price;

	public:

		Book();

		void setTitle(string s);

		void setPrice(double p);

		string getTitle() const
		
		{return title;}


		double getPrice() const
		
		{return price;}

		bool hasKeyword(string key);


	
};

Book::Book()
{
	title="None";
	price=0;
}

void Book :: setTitle(string s)
{
	title=s;

}

void Book::setPrice(double p)
{
	if(p>0)
	{
		price=p;
	
	}

	else
	{
		price=0;
	}

}
void Initalize(Book *book, int size)
{

	for(int i=0;i>size;i++)
	{
		string T;
		double P;

		cout<<"Enter the title: ";
		cin>> T;
		

		cout<<"Enter the price: $";
		cin>>P;
		
		book[i]=new Book(T,P); 

	}

The error occur here. It says "no overloaded function takes 2 arguments

}
const int SIZE=3;

int main()
{

	int number;	
	string key;

		
	cout<< "Enter the number of books: ";
	cin>> number;
	Book *book=0;
	book=new Book[number];


	Initalize(book,number);

	cout<<"Enter the keyword: ";
	cin>>key;
        delete[] book;
	book=0;


	system ("pause");
	return 0;

}

Can you fix this error?

Recommended Answers

All 6 Replies

>>book=new Book(T,P);

The error is telling you that the Book class does not have a constructor that takr two arguments. You need to add another constructor that takes two strings.

is there anyway to put title and price into book without making another constructor?

Look at the methods of the Book class and see if you don't find a way to do that.

use constructor with default parameters

// change your prototype to this one
Book(string, double);
// and the function to this
Book::Book( string ti = "None",double pri =0)
{
	title=ti;
	price=pri;
}

use constructor with default parameters

// change your prototype to this one
Book(string, double);
// and the function to this
Book::Book( string ti = "None",double pri =0)
{
	title=ti;
	price=pri;
}

sorry but i had posted it twice by mistake

if this answer is what our looking for mark it as solved
thanks

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.