#include<iostream>
usingnamespace std;
class Area
{
Area(int , int );
int length;
int width;
int* IN_DATA();
int CAMPUS_AREA(int []);
void DISPLAY(int);
} ;
Area::Area (int a, int b)
{
length=a;
width=b;
}
int main()
{
system("pause");
}
When I declare an object of type area, it gives an error, that no matching function to call to Area::Area(). and I want to call class functions in main, but it gives an error that, you cannot call function without object..and, when I declare object it gives the above error. Help!
If you ever want to be able to use DISPLAY() or CAMPUS_AREA in main, you'll need to define them under the access specifier public: . By Default all class members are private unless you specify otherwise.
Set your access specifier in Area:
1 2 3 4 5 6 7 8 9 10 11 12
class Area
{
int length;
int width;
public: // Access Specifier
Area(int , int );
int* IN_DATA();
int CAMPUS_AREA(int []);
void DISPLAY(int);
} ;
Everything after the public: access specifier allows your class methods to be accessed outside of the class itself. Where as your two variables, length and width are private, and can only be altered from the public methods within the Area class.
This isn't a fix all solution, this helps you get on your way. I suggest you read the tutorial here on classes: http://www.cplusplus.com/doc/tutorial/classes/ - I'll be reading it more in depth as well.