Reputation: 341
There is some simple C++ console app where I've got Utility.h
which looks like this
#pragma once
#include "stdafx.h"
using namespace std;
class Utility
{
public:
Utility();
~Utility();
static Plane* getPlanes(const char* fileName);
static arma::vec getDirectionVector(int phi, int theta);
};
and I've got Utility.cpp
which looks like
#include "stdafx.h"
#include "Utility.h"
Utility::Utility()
{
}
Plane* Utility::getPlanes(const char* fileName)
{
const char *p_chInputFileName = fileName;
ifstream *p_inFileStream;
Plane *p_confiningPlanes;
..........................................
.........................................
return p_confiningPlanes;
}
arma::vec getDirectionVector(int phi, int theta)
{
arma::vec direcitonVector(3);
direcitonVector.at(0) = cos(theta) * cos(phi);
direcitonVector.at(1) = cos(theta) * sin(phi);
direcitonVector.at(3) = sin(theta);
return direcitonVector;
}
Utility::~Utility()
{
}
I also have some other files in my project which I don't think are important.
My compiler keeps telling me that ; is missing before *
and that type specifier is missng and int is assumed
in line
static Plane* getPlanes(const char* fileName);
I have no clue about what is happening and this problem came up after I deleted from and added again to my project some classes and probably something else.
Upvotes: 1
Views: 54
Reputation: 2520
You need to tell the compiler about Plane
.
The most basic way of doing this is to include the header that defines Plane
in Utility.h
.
A more advanced way of doing this is to forward declare the class or struct by adding class Plane;
or struct Plane;
, as appropriate, to Utility.h
before class Utility
, and then include the header that defines Plane
in Utility.cpp
. You can do this because in the header you only have a pointer to Plane
, and therefore the compiler only needs to know of it's existence. While to use it you need to include the definition of the class/struct.
Upvotes: 0
Reputation: 180585
In utility.h
you have
static Plane* getPlanes(const char* fileName);
But there is nothing in the header file to tell the compiler what a Plane
is. You either need to include the file that has the Plane
type in it or forward declare it in your header file.
Upvotes: 1
Reputation: 129011
I’m guessing it doesn’t realize that Plane
is a class, and thinks instead you’re trying to declare a static member named Plane
(and warns you that it’s assuming it’s of type int
since you didn’t give it a type).
Add struct Plane;
before class Utility {
in your Utility.h
to forward-declare Plane
, which should make it understand that Plane
is a type, not the name of a member you’re trying to declare, and hence solve your problem.
(I should also note that many people frown on using namespace std;
at the top level in header files.)
Upvotes: 1