Jump to content
  • Advertisement
Sign in to follow this  
Devil0150

visual c++ error messages

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 1
class myClass
{
...
};

// file 2
class myClass;

class otherClass
{
myClass *somePtr;
};

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!