Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //################ t1.h #################
- template <class T>
- struct C
- {
- static int count;
- };
- template <class T> int C<T>::count = 0;
- //################ a.cpp #################
- #include "t1.h"
- #include <iostream>
- void a_print()
- {
- C<void>::count++;
- std::cout << "a_print: " << C<void>::count << std::endl;
- }
- //################ b.cpp #################
- #include "t1.h"
- #include <iostream>
- void b_print()
- {
- C<void>::count++;
- std::cout << "b_print: " << C<void>::count << std::endl;
- }
- //################ main.cpp #################
- void a_print();
- void b_print();
- int main()
- {
- a_print();
- b_print();
- }
- //################ Makefile #################
- all: test
- test : main.o a.o b.o
- g++ -o $@ $^
- clean:
- rm -rf *.o test
- //################ OutPut #################
- ~$ make
- g++ -c -o main.o main.cpp
- g++ -c -o a.o a.cpp
- g++ -c -o b.o b.cpp
- ~$ ./test
- a_print: 1
- b_print: 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement