主要.cpp:
#include <iostream>
#include "Person.hpp"
int main()
{
std::cout << "HELL!\n";
Person a{"Jiraya"};
std::cout << a.getName() << "\n";
a.setName("Niko");
a.do_smt();
}
Run Code Online (Sandbox Code Playgroud)
人.hpp:
#pragma once
#include <string>
using std::string;
class Person
{
private:
string name;
public:
Person();
Person(const string &n);
void do_smt();
string getName(){return name;}
void setName(const string& n);
Run Code Online (Sandbox Code Playgroud)
人.cpp:
#pragma once
#include <iostream>
#include "Person.hpp"
Person::Person(const string &n) : name{n}
{
}
void Person::setName(const string &n)
{
name = n;
} …Run Code Online (Sandbox Code Playgroud)