Jump to content
  • Advertisement
Sign in to follow this  
Madolite

random Compiler Error C2143 - missing ";" before "*"

This topic is 862 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

Hey are anyone able to tell me wth is going on here? I've been experimenting with stdafx.h precompiled header.

 

#pragma once
/*I get all includes from #include "stdafx.h",which I've been explained should be located in the .cpp file
The SDL_'s are fully capable of finding the SDL.h file included in stdafx.h
*/
    class Display
    {
    public: Display(int width, int height, const std::string& title);

    void update();

    ~Display();
protected:
private:

    //... AND YET, I get an compiler Error C2143 in the line below: "syntax error : missing ';' before '*'"
    SDL_Window* window;  <-- This line

    SDL_Renderer* renderer;
    SDL_Texture* image;
    SDL_Rect bgRect;
    SDL_Rect imageRect;
};

 

So what am I doing wrong? Btw, I haven't actually done anything to explicitly precompile the header, I've just created stdafx.h for now and put all #includes inside that file.

 

Or am I just blind? Thanks for input.

Edited by Madolite

Share this post


Link to post
Share on other sites
Advertisement
Visual Studio? You’ll need to configure your project to “Use Precompiled Headers”, and configure stdafx.cpp to “Create Precompiled Header”.

Share this post


Link to post
Share on other sites

That syntax error almost always means that the compiler can't find the struct/class that you're referring to.  Does the header include stdafx.h, or just the source file?  If not, you'll either need to include it there or forward declare your structs.

 

I'm an idiot.  Make sure your #include "stdafx.h" line in your accompanying cpp file is included first, before anything else.  That's required for precompiled headers anyway, but it will lead to what you're seeing whether the header is precompiled or not.  That said, you should still forward declare your pointer types used in headers, because it's good practice.

Edited by SeraphLance

Share this post


Link to post
Share on other sites

Ah ok, I think I get it now. I'll mess around with what fastcall said. Thanks. And yeah, VS2015

Edited by Madolite

Share this post


Link to post
Share on other sites

Visual Studio? You’ll need to configure your project to “Use Precompiled Headers”, and configure stdafx.cpp to “Create Precompiled Header”.

 

Ok, so I've done this, but I have another problem:

If I put:

 
const std::string TITLE = "gameTitle";
 
...inside foo.h (currently private) and only #include <string> inside the stdafx.h that I linked in foo.cpp,
I'm being told that "string is not a valid member of std" (C2039)
 
Putting #include <string> inside foo.h fixes it though. But that should defeat the whole purpose of stdafx.h

---------------
Edit: Weird, creating that precompiled header didn't actually solve anything. o.O
I think I'll put it on the shelf for now and just redo the whole thing later, when I got less on my plate. Too many changes to my recently. :/

Thanks anyways.
Edited by Madolite

Share this post


Link to post
Share on other sites

You shouldn't put that in the header.  It is both the declaration and the definition.

 

By putting that in a header file, you create a new instance of that object in every cpp file.

 

 

 

Declare it (announce that it exists) in the header.  That's with: extern const std::string TITLE;

 

Define it (actually create an instance) in a single C++ file. That's with: const std::string TITLE = "gameTitle";

 

The compiler will note that it says 'extern' and doesn't actually create an instance, so it will include a marker that it needs to find the object at link time.  The linker will notice the marker, find the file that has a real instance, and replace the marker with the actual object address.

Share this post


Link to post
Share on other sites
If you require the inclusion of a precompiled header (stdafx.h) for your code to work, it's broken. If you manually include your precompiled headers in your cpp files, your project is broken.

You should use the force include mechanism to include PCHes and should frequently test that your build works without them.

And this is because your project is broken off you're including stiff like SDL in your precompiled headers. Only a tiny fraction of source code should be accessing something like SDL directly.

Put only very common headers into PCHes, and then regularly make sure to cull things from them. Test build without PCHes so you know that adding or removing files from them are poorly optimizations and nothing more.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!