我有一个奇怪的问题,这是我的代码:
test.h
#ifndef _test_
#define _test_
#include <iostream>
#include <string>
class Test {
public:
Test();
~Test();
void addName(std::string _Name);
private:
std::string Name;
};
#endif // _test_
Run Code Online (Sandbox Code Playgroud)
TEST.CPP
#include "test.h"
Test::Test() {}
Test::~Test() {}
void Test::addName(std::string _Name) {
std::cout << _Name << std::endl;
Name = _Name;
std::cout << _Name << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include "test.h"
int main(int argc, char* argv[]) {
Test* project;
project->addName("abc");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
结果:
ABC
该计划意外完成.