Object decleration problem.

+1 sowmyaraj g · June 10, 2015
I am following c++ tutorials in tutorial 42,43 iam getting an error while declearing object in classes
i decleared as:sally so;
Please help me in rectifing my mistake.

Post a Reply

Replies

Oldest  Newest  Rating
0 Laura Lee · June 11, 2015
Does your object have a constructor?
class Person
{

}
0 Laura Lee · June 11, 2015
Accidently posted.
#include 
using std::cout;
using std::endl;
class Person
{
private:
unsigned int age;
public:
Person::Person(int age)

this->age = age;
}
Person::~Person()
{

}
unsigned int getAge()
{
return age;
}
};

int main()
{
Person person(15);
cout
In order to instantiate an object, it needs a constructor. And if the constructor requires arguments, they need to be passed into the initialization of the object.
0 Laura Lee · June 11, 2015
I'm done posting on this website. It's code tags are rediciulous and unformatted.
0 sowmyaraj g · June 12, 2015
What is object constructor.
0 Zachary B · June 13, 2015
A constructor is created every time an object is called. 

for example in the person class.

class Person:
{
          public:
                    Person() { age = 0;}

}

Person() is the constructor, whenever the object is created the age will be set to zero. So for example

Person sally; 

sally's default age (when the object was created) will be set to zero; 
  • 1

C++

107,324 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator