Last active
March 16, 2017 21:55
-
-
Save Steve132/b52533f41b7b2e7ccf04c12b9a2095d6 to your computer and use it in GitHub Desktop.
Example Circular Include Failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ g++ -c -o Foo.o Foo.cpp | |
Foo.cpp:3:1: error: redefinition of `Foo::Foo()' | |
Foo::Foo() | |
^ | |
In file included from Foo.h:11:0, | |
from Foo.cpp:1: | |
Foo.cpp:3:1: note: `Foo::Foo()' previously defined here | |
Foo::Foo() | |
^ | |
Foo.cpp: In function `void member()': | |
Foo.cpp:6:6: error: redefinition of `void member()' | |
void member() | |
^ | |
In file included from Foo.h:11:0, | |
from Foo.cpp:1: | |
Foo.cpp:6:6: note: `void member()' previously defined here | |
void member() | |
^ | |
$ g++ -c -o main.o main.cpp | |
$ g++ main.cpp Foo.cpp -o main | |
Foo.cpp:3:1: error: redefinition of `Foo::Foo()' | |
Foo::Foo() | |
^ | |
In file included from Foo.h:11:0, | |
from Foo.cpp:1: | |
Foo.cpp:3:1: note: `Foo::Foo()' previously defined here | |
Foo::Foo() | |
^ | |
Foo.cpp: In function `void member()': | |
Foo.cpp:6:6: error: redefinition of `void member()' | |
void member() | |
^ | |
In file included from Foo.h:11:0, | |
from Foo.cpp:1: | |
Foo.cpp:6:6: note: `void member()' previously defined here | |
void member() | |
^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Foo.h" | |
Foo::Foo() | |
{ | |
} | |
void member() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FOO_H | |
#define FOO_H | |
class Foo | |
{ | |
public: | |
Foo(); | |
void member(); | |
}; | |
#include "Foo.cpp" | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Foo.h" | |
int main() | |
{ | |
Foo f; | |
f.member(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment