visual c++ error messages

Started by
18 comments, last by Devil0150 14 years, 7 months ago
I get some error messages when I try to compile my code. I have two classes: class myClass { ... }; class otherClass { ... myClass* somePtr; }; This is one of the error messages I get when I try to compile. error C2143: missing ';' before '*' This error happens at the line where I declare the myClass pointer. And the declaration in the line before that, DOES have a ';' in the end. Any help how I can fix this. (I have all my code in one file).
Advertisement
that shouldn't cause a problem, maybe another error in other place causes this? (probably in class myClass{...};)
taytay
This is it. Anything wrong here?

class myClass
{
myClass();
std::string name;
short first, second, third, fourth, fifth;
short pp;
};

The constructor is empty


myClass()
{
}
constuctors should be public, try changing it

class myClass
{
public:
myClass();
std::string name;
short first, second, third, fourth, fifth;
short pp;
};

also if you define a function of a class outside of a class you should use this


myClass::myClass()
{
}
taytay
I wrote public in the class declaration. The constructor is like you said(myClass::myClass()), but the error is still there.
I guess you're not showing us all of the code. Look at the file being compiled when the error was show (The output will show the name of the .cpp file); work your way up the includes to where otherClass is and see if myClass was declared at any point before it. I'm guessing that it isn't.
The problem is that you've got those two class defined in separate files, right? In that case you need to forward-declare myClass before otherClass, like so:
// file 1class myClass{...};// file 2class myClass;class otherClass{  myClass *somePtr;};
Quote:Original post by Devil0150
(I have all my code in one file).


thats a bad habbit to get into
but for now it would eliminate the need to forward declare your class.. hmm is that all of your code?

edit:: btw if no one replies to your accident thread, you can edit and delete your post.

also, this is working code so check what you have on yours compared.
class MyClass{	int one, two, three;public:	MyClass()	{	}};class ClassTwo{	int one, two;	MyClass* ptr;public:	ClassTwo()	{	}};

class myClass{public:      myClass();      std::string name;      short damage, defense, spDamage, spDefense, speed;      short pp;};myClass::myClass(){}class otherClass{public:       otherClass();       void Attack();       void Run();       bool isWild;       string name;       short number;       string type1;       string type2;       otherClass* Evolution;       myClass* myATKs;             /*this is where I get the error*/       myClass* chosenATK;private:       short atkLVL[];        short chooseATK();       void ListATK();};


This is my code in the two classes. I dont know if this is that much important but I get two other errors on the same line:
error C4430: missing type specifier - int assumed. Note: C++ does not support default int
try std::string instead of just string..
mebeh you forgot to put

using namespace std;

This topic is closed to new replies.

Advertisement