Hi, I declared and implemented a print() function in a class. But when I call this function it is giving me an error: which says that function does not take 0 arguments. But what should my arguments be.

I have posted the part of the code for more specification.
Thanks.

/************class header******************************/

class addressType
{
private:
	string St_address;
	string city, state;
	int Zip;

public:
	void  print_add(string, string, string, int);
	void get_add();
	void set_add(string, string, string, int);
	addressType();
	~addressType();
};
#endif

/*****************implementation of print & set function*****/

void addressType::set_add(string street, string cit, string st, int zip)
{

   	St_address = street;
	city = cit;
	state = st;
	Zip = zip;

	print_add(St_address, city, state, Zip);

	return;

}
void addressType::print_add(string str, string Cit, string St, int Z)
{
	cout<<"Address: "<<str<<endl;
	cout<< Cit <<","<<St<<endl;
	cout<<"Zip: "<<Z<<endl;

	return ;

}

/******** main()********************/
int main()
{
	addressType Avi;
	Avi.get_add();
	Avi.print_add(); //error C2660 function does not take 0 arguments. 
I am trying to print the user's address here.


	return 0;
}

Recommended Answers

All 5 Replies

The method you are calling is print_add, not print. From the code you posted print_add is defined as: void addressType::print_add(string str, string Cit, string St, int Z). That means it takes three strings and one integer. You do not have a method called print() implemented, but if you did it might look something like this:

void addressType::print()
{
cout << St_address << endl;
cout << city << ", " << state << " " << zip << endl;
}

I agree with ninwa, the function you have doesn't make much sense.

void addressType::print_add(string str, string Cit, string St, int Z)
{
	cout<<"Address: "<<str<<endl;
	cout<< Cit <<","<<St<<endl;
	cout<<"Zip: "<<Z<<endl;

	return ;

}

The function asks you pass in all of the address data when the address data is already in the class. (Though your sample doesn't show how the address data got in there.)

You could write the print method as shown by ninwa, or if you prefer your output format:

void addressType::print_add()
{
	cout << "Address: " << St_address << endl;
	cout << city << "," << state << endl;
	cout << "Zip: " << Zip << endl;
}

Additional comments:

#1 If you have a function with a void return type, the return statement at the end of the function is not necessary.

#2 It is a good idea to establish naming conventions for your classes and members. The one that stood out the most to me as not matching were the names of the data members. You have a leading capital letter on 2 of them and leading lower-case on the other 2. It probably should be one way or the other, but not both.

well dont u see the prototype of the function print_add
.the print_add function takes 4 paramters when u declare and define inside the class. But while calling the function in the main u havent passed any paramters.

Moreover what does get_add will give u when u dint even set the address!
Moreover set the address in the constructor of the class and no use of get_add function.And no need of passing any parameter in the print_add function,coz you will be printing the member variables of the function which will be set when u call the set_add function.

Revert me back for any issues!
thanks
som shekhar

class addressType
{
private:
string St_address;
string city, state;
int Zip;


public:
void  print_add(string, string, string, int);
void get_add();
void set_add(string, string, string, int);
addressType();
~addressType();
};
#endif


/*****************implementation of print & set function*****/


void addressType::set_add(string street, string cit, string st, int zip)
{


St_address = street;
city = cit;
state = st;
Zip = zip;


print_add(St_address, city, state, Zip);


return;


}
void addressType::print_add(string str, string Cit, string St, int Z)
{
cout<<"Address: "<<str<<endl;
cout<< Cit <<","<<St<<endl;
cout<<"Zip: "<<Z<<endl;


return ;


}


/******** main()********************/
int main()
{
addressType Avi;
Avi.get_add();
string foo,hoo,koo;
foo="rrr";hoo="aaa";koo="ppp"
Avi.print_add(foo,hoo,koo,5);//use this
//your mistake was that actually your function takes 4 arguments:: 3 strings and 1 integer


return 0;
}

the function you declear in the class{}; has three paraments but^^ you know ?

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.