Last active
July 6, 2022 00:35
-
-
Save davidberard98/716679a9bae7ba76f37a224943cdcdf1 to your computer and use it in GitHub Desktop.
duplicate build
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++ counter.cpp -c -o counter.o | |
g++ x.cpp -c -o x.o | |
g++ x.cpp -c -o y.o | |
g++ main.cpp -c -o main.o | |
g++ counter.o x.o y.o main.o -o main |
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 "counter.h" | |
int& counter() { | |
static int cnt = 0; | |
return cnt; | |
} | |
CounterIncr::CounterIncr() { | |
counter() += 1; | |
} |
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
int& counter(); | |
struct CounterIncr { | |
CounterIncr(); | |
}; |
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 <iostream> | |
#include "counter.h" | |
int main() { | |
std::cout << "Counter: " << counter() << std::endl; | |
return 0; | |
} |
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 <iostream> | |
#include "counter.h" | |
namespace { | |
CounterIncr ci; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment