0
#include <iostream>

using namespace std;

class A
{
private:

	int a;

};

A::A()
{
	a = 10;
}

int main()
{ 
	A obj1;

	cin.ignore();
	cin.get();

}

It is giving me the error

Error 1 error C2600: 'A::A' : cannot define a compiler-generated special member function (must be declared in the class first) c:\documents and settings\levi\desktop\stfu\stfu\main.cpp 14

Am I just completely forgetting to do something? The error message makes it sound like A is a function, when Im just trying to declare a variable using a default constructor. Help please!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by firstPerson
0

If you provide a definition for the constructor for that class, you need
to define the constructor. That statement is what the error is saying.
For example :

Correct way

class Test{
  int i;
public:
  Test();
};
Test::Test(){ i = 10; }

Incorrect or wrong

class Test{
 int i;
};
Test::Test(){ i = 10; }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.