64,684
社区成员
发帖
与我相关
我的任务
分享
//test.h
#ifndef TEST_H
#define TEST_H
#include <iostream>
#include <string>
class Test
{
public:
std::string STR1;
std::string STR2;
static int static_init() {
std::cout << "static_init" << std::endl;
return 0;
}
void set_str();
void display();
};
//test.cpp
#include "test.h"
using namespace std;
void Test::set_str() {
STR1 = "STR1 static init";
STR2 = "STR2 static init";
}
void Test::display() {
cout << "STR1" << STR1 << endl;
cout << "STR2" << STR2 << endl;
}
static int result = Test::static_init();
#endif // TEST_H
// vim: set ts=4 sw=4 sts=4 et:
// main.cpp
#include <iostream>
#include "test.h"
using namespace std;
int main()
{
cout << "Start" << endl;
Test t1;
}
static_init
static_init
Start
all: main
test.o: test.cpp test.h
g++ -c test.cpp -o test.o
main.o: main.cpp
g++ -c main.cpp -o main.o
main: test.o main.o
g++ test.o main.o -o main
clean:
rm -f ./*.o main
.PHONY: main