Reputation: 813
// practice.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
class one;
int main()
{
one alpha;
cin.get();
}
class one
{
};
I have no idea why the above method is producing an error: object uses undefined class. Any help would be nice.
Upvotes: 0
Views: 58
Reputation: 1
Compiler need to know the full definition of the class before you define an object,if you want to define the class lately, you can define a pointer or reference first, and initlize it after you define the class
Upvotes: 0
Reputation: 11
You need to define class before you use it. forward declaration works only for pointers, but that is not the way you are using.
Upvotes: 0
Reputation: 21763
Forward-declaring allows you to create a pointer or reference to a class. However, in order to use the class, which includes creating an instance of it, the full class definition is required by the compiler at that point.
Upvotes: 3