小编rai*_*jin的帖子

vscode g++ 找不到 .cpp 定义文件

我正在尝试使用多个 .cpp 和 .hpp 文件编译 C++ 示例,但 g++ 找不到任何成员函数定义。


主要.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)

c++ g++ visual-studio-code

1
推荐指数
1
解决办法
1466
查看次数

标签 统计

c++ ×1

g++ ×1

visual-studio-code ×1