dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2018
    Posts
    4

    [RESOLVED] 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. (I have marked both in my code)

    Piece.h

    Code:
    #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(); //--Line 12----Error here------
    };
    
    class Pawn : public Piece // derive class Pawn from class Piece (inheritance)
    {
    public:
    	bool isWhite(); //Determine which direction pawn can move in based on if it is White or Black
    	string static legalMoveP(int); //---Line 19------error here---
    
    };
    
    class Rook : public Piece
    {
    public:
    	void legalMoveR();
    };
    
    class Bishop : public Piece
    {
    public:
    	void legalMoveB();
    };
    
    class Knight : public Piece
    {
    public:
    	void legalMoveN();
    };
    
    class Queen : public Piece
    {
    public:
    	void legalMoveQ();
    };
    
    class King : public Piece
    {
    public:
    	void legalMoveK();
    };
    
    #endif
    Thank you for your help.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,144

    Re: Error C2144 and error C4430

    Quote Originally Posted by Aroom View Post
    Code:
    ...
    class Piece {
    public:
    	bool static kingSafe(); //Check if king is safe
    	string static currentPosition(); //--Line 12----Error here------
    };
    ...
    Did you try
    Code:
    	static string currentPosition();
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,210

    Re: Error C2144 and error C4430

    string is part of the std:: namespace. So

    Code:
    std::string static currentPosition(); //--Line 12----Error here------
    and likewise for the other uses of std:: classes, functions etc
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.1)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)