setting default value for the function

Hi,
I am trying the set the default value of the function of the class.
but this code gives me error . I am not able to find how to set the default value of the function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include < iostream>
using namespace std; 
class TestA
{
	private:
			int a, int b; 
	public:
			TestA() { } 
			void SetValue( int _a = 5  , int _b  = 50 ) ; 
			~TestA() {}
};
void TestA::SetValue(int _a  , int _b ) 
{
	a = _a ; 
	b = _b; 
	cout<<"\n Value of a = "<<a ;
	cout<<"\n Value of b = "<<b;
}
int main()
{
	TestA aa ;
	int x , y ;
	aa.SetValue(x y );			//I need to print the default value in this function 
	return 0 ; 
}


please help me with the function .

getting these errors

e
rror: ISO C++ forbids declaration of ‘SetValue’ with no type
error: prototype for ‘int TestA::SetValue(int, int)’ does not match any in class ‘TestA’
error: candidate is: void TestA::SetValue(int, int)
error: ‘int TestA::SetValue(int, int)’ cannot be overloaded
 error: with ‘void TestA::SetValue(int, int)’


Thanks in advance .
Last edited on
A few syntax errors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;
class TestA
{
	private:
			int a, b;
	public:
			TestA() { }
			void SetValue( int _a = 5  , int _b  = 50 );
			~TestA() {}
};
void TestA::SetValue(int _a  , int _b )
{
	a = _a ;
	b = _b;
	cout<<"\n Value of a = "<<a ;
	cout<<"\n Value of b = "<<b;
}
int main()
{
	TestA aa ;
	//int x , y ;
	aa.SetValue();//x, y);			//I need to print the default value in this function
	return 0 ;
}
Last edited on
aa.SetValue(x y );
should be
aa.SetValue(x, y );
aa.SetValue();//x, y); //I need to print the default value in this function

Well then you'd best write a member function that takes no parameters. You can't call functions that don't exist.
Thanks naraku9333 , and Moschops ,, for your tips it worked . . cheers
Topic archived. No new replies allowed.