An error occurred while passing the structure declaration: "has a previous declaration here"

When creating my small C ++ project, I get the following 2 errors, I can not understand the reason:

  • error: using typedef-name 'TTF_Font' after 'struct'.
    Points to the following line of code: struct TTF_Font;in Foo.h.

  • error: "TTF_Font" has the previous declaration here.
    Points to the following line of code: typedef struct _TTF_Font TTF_Font;in SDL_ttf.h.

I narrowed it down to the following files in a new test project:

foo.h:

#ifndef FOO_H
#define FOO_H

struct TTF_Font;

class Foo
{
    TTF_Font* font;
};

#endif // FOO_H

foo.cpp:

#include "Foo.h"
#include "SDL/SDL_ttf.h"

// No implementation, just testing

main.cpp:

#include "Foo.h"
int main(int argc, const char* argv[])
{
    Foo a;
    return 0;
}

Do you guys know what I'm doing wrong?

- TTF_Font, SDL_ttf. , , . , .

struct TTF_Font;, #include "SDL/SDL.ttf.h", . , , , : -).

: IDE Code:: Blocks IDE mingw32. SDL. ++, #.

+5
2

, .

:

struct TTF_Font;

, TTF_Font typedef, struct:

typedef struct _TTF_Font TTF_Font;

stuct _TTF_Font.

typedef , typedef , struct typedef, , , .

+8

, :

struct foo_t;

typedef struct foo { ... } foo_t;

forward , typedef. struct foo;, struct foo.

+2

All Articles