Public Group

# visual c++ error messages

This topic is 3294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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).

##### Share on other sites
that shouldn't cause a problem, maybe another error in other place causes this? (probably in class myClass{...};)

##### Share on other sites
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()
{
}

##### Share on other sites
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()
{
}

##### Share on other sites
I wrote public in the class declaration. The constructor is like you said(myClass::myClass()), but the error is still there.

##### Share on other sites
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.

##### Share on other sites
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;};

##### Share on other sites
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()	{	}};

##### Share on other sites

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

##### Share on other sites
try std::string instead of just string..
mebeh you forgot to put

using namespace std;

1. 1
2. 2
Rutin
23
3. 3
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• ### Forum Statistics

• Total Topics
632579
• Total Posts
3007169

×