Error C2144 and error C4430

First of all I realise that there are a number of posts about this error and they all describe how there is usually a semicolon missing before the error mentioned line, and in some cases they are refering to a different header file.

While I am not eliminating the possibility of my problem being a semicolon that I have missed, but it is not one that I have been able to find.

Now to the error, as the title suggests I am getting the error C2144 "syntax error: 'int' should be preceded by ';'" and error C4430 "missing type specifier - int assumed. Note: C++ does not support default-int" on lines 12 and 19 respectively in my Piece header file. (Note I am getting both errors on both lines, I have marked them in my code)

Piece.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef PIECE_H
#define PIECE_H
#include <string>

//abstract/base class
class Piece {
public:
	bool static kingSafe(); //Check if king is safe
	string static currentPosition(); //---Error
};

class Pawn : public Piece // derive class Pawn from class Piece 
{
public:
	//bool isWhite(); //Determine which direction pawn can move in based on if it is White or Black
	string static legalMoveP(int); //---Error--

};


#endif 


Thank you for your help.
Last edited on
Are those the only errors/warnings being generated by your compiler?

Did you perhaps forget to #include a necessary #include file or perhaps forgot to properly scope something from the std namespace?

Hello Arooom,

Welcome to the forum.

Missing the header file and main, so I can not compile your program to see what is happening. I do get the 4430 error because of the missing header file. It says that JustABoard in JustABoard CurrentGame is not a type and that "int" is assumed and the rest.

Now to the error, as the title suggests I am getting the error C2144 "syntax error: 'int' should be preceded by ';'"
This is nice, but what line in which file does this refer to. You have left out important information. It is best to include the whole error message with line numbers and file.

Right now I can not duplicate your errors with out all the files and with the 127 error messages I do get some direct me to the "board.h" header file I do not have.

Not knowing what main looks like I can not say if any of your errors start there.

It is best to include all the files, because sometimes the error is not always where you think it is.

Hope that helps,

Andy
@jlb No I I receive other warnings when I try to compile but I do assume that they are connected to the errors stated above.

@Handy Andy Thank you for your reply. I did state that the errors are on line 12 and 19 of my header file that I included. I also included an edited cpp file with only relevant code to the problem so as I don't spam the post with code. I did not think others would like to compile to see the problem for themselves.
Last edited on
Lines 12 and 19? What is a "string"?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef PIECE_H
#define PIECE_H
#include <string>

// base class
struct Piece {
	static bool kingSafe();
	static std::string currentPosition();
};

struct Pawn : public Piece
{
	static std::string legalMoveP(int);
};

#endif 
Sorry, I use
 
using namespace std;

because I'm not used to coding without it yet. I'm new to programming, even more to C++.

As to if you are suggesting to me to switch the location of "static" and "std::string", then it still results in an error for me. " Error C3646: unknown override specifier ", " Error C2059: syntax error: ')' " and " Error C2238: unexpected token(s) preceding ';' " on both line 12 and 19 again.
Last edited on
I hope you're not using that statement inside the header file which is where the problem is occurring!

And note your code posted in post #1 does not (thankfully) have the using statement in that header.

I can't believe I missed that, and I will try to avoid using it.
Thank you for your help.
Hello Arooom,

Thank you for the files they are just what I needed.

Sometimes it helps me to have all the files, so I can see exactly what is happening. And complete files make a big difference. I am good, but some programs just need the long way around.

Sorry after I posted the message I did find the comments on the lines 12 and 19. Speaking of those lines I did figure that you need to qualify "string" with "std::". Once I did that the program compiled.

Before you think of adding the line using namespace std:: to your header files read this: http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/

I did have four warnings that variables "k" and "p" in the Definitions file are "unreferenced local variable"s. This generally means that you defined a variable, but never used it even though I see it being used in the while condition at the bottom of the function. These are only warnings for me. Nothing to stop it from compiling, but may be a problem at run time.

Hope that helps,

Andy
Hello Arooom,

I saw the other posts after I finished mine.

Sorry, I use
"using namespace std;"
because I'm not used to coding without it yet. I'm new to programming, even more to C++.

Now is the best time to learn when it is a little at a time instead of all at once later.

Andy
Topic archived. No new replies allowed.