小编Cam*_*ilo的帖子

是否可以在C++中获取对象的包含文件的名称?

我需要从类中实例化一个对象,比如说Cat,并且知道它包含的文件的名称.

主程序看起来应该是这样的:

    #include <iostream>
    #include <vector>
    #include "Cat.h"

    using namespace std;

    vector<string> getIncludes(Cat cat){
      ...
    }

    int main(int argc, char *argv[])
    {
      Cat cat;
      std::vector<string>list = getIncludes(cat);
    }
Run Code Online (Sandbox Code Playgroud)

Cat类头文件将是这样的:

    #include "utils.h"
    #include "animals.h"

    class Cat{
    public:
      Cat();
      ~Cat();
      void meow();
    private:
      int age;
    }
Run Code Online (Sandbox Code Playgroud)

打电话后std::vector<string> list = getIncludes(cat),list应该包含"utils.h""animals.h".

如果还有另一种方法可以在主函数中获取这些名称,我愿意接受建议.先感谢您.

c++

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

标签 统计

c++ ×1