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.
#include < iostream>
usingnamespace 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)’
#include <iostream>
usingnamespace 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 ;
}