Reputation: 1721
#include "stdafx.h"
using namespace System;
class Calculater; // how to tell the compiler that the class is down there?
int main(array<System::String ^> ^args)
{
::Calculater *calculater = new Calculater();
return 0;
}
class Calculater
{
public:
Calculater()
{
}
~Calculater()
{
}
};
Im declaring the class after main, how do i tell the compiler were my class is? i tried
class Calculater; before main but its not working.
Upvotes: 5
Views: 10254
Reputation: 46249
You can have pointers to Calculator after your pre-declaration. The problem is the constructor (new Calculator()
), which hasn't been defined at that point. You can do this:
Before main:
class Calculator { // defines the class in advance
public:
Calculator(); // defines the constructor in advance
~Calculator(); // defines the destructor in advance
};
After main:
Calculator::Calculator(){ // now implement the constructor
}
Calculator::~Calculator(){ // and destructor
}
Upvotes: 6
Reputation: 29724
put class definition before main:
#include "stdafx.h"
using namespace System;
class Calculater
{
public:
Calculater()
{
}
~Calculater()
{
}
};
int main(array<System::String ^> ^args)
{
Calculater *calculater = new Calculater();
return 0;
}
Upvotes: 1
Reputation: 37122
You can't do it how you've written it. The compiler has to be able to see the definition of the class before it can use it. You need to put your class before your main
function, or preferably in a separate header file which you include.
Upvotes: 6