将C ++方法声明从.hh移动到.cc文件 [英] Moving C++ Method Declarations from .hh to .cc File

查看:182
本文介绍了将C ++方法声明从.hh移动到.cc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个C ++项目,其中有很多类,有类,方法,并包括在一个单一的文件。这是一个大问题,因为经常方法实现需要#include语句,并且任何想要使用类的文件都将继承这些#include。我只是想,有一个工具,在C ++头文件上进行以下操作是很好的:

I'm working on a C++ project in which there are a lot of classes that have classes, methods and includes all in a single file. This is a big problem, because frequently the method implementations require #include statements, and any file that wants to use a class inherits these #includes transitively. I was just thinking that it would be nice to have a tool that did the following operation on a C++ header file:


  1. 解析C ++头文件文件分为两部分:一个头文件,声明一个类,它的数据和该类的方法,以及一个实现方法的单独文件。

  2. 从头文件中删除不必要的包。

  3. 将必要的内容添加到实施文件中。

我理解,解析C ++非常困难,但即使是不完美的工作将是一个改进重复的文本编辑,我现在正在做。有什么东西这样吗?

I understand that parsing C++ is very difficult, but even something that worked imperfectly would be an improvement over the repetitive text editing that I'm doing right now. Is there anything that does anything like this? Or am I stuck with the decision between rolling my own solution or hammering through this with my text editor?

推荐答案

您是否正在寻找像 Lazy C ++

Are you looking for something like Lazy C++?


Lzz是一个自动化许多
繁重的C ++编程任务的工具。它可以
节省了大量的时间,使编码
更愉快。给定一系列
声明,Lzz将生成您的
头文件和源文件。

Lzz is a tool that automates many onerous C++ programming tasks. It can save you a lot of time and make coding more enjoyable. Given a sequence of declarations Lzz will generate your header and source files.

    // A.lzz
    class A
    {
    public:
      inline void f (int i) { ... }
      void g (int j = 0) { ... }
    };
    bool operator == (A const & a1, A const & a2) { ... }

Lzz will generate a header file:

    // A.h
    #ifndef LZZ_A_h
    #define LZZ_A_h
    class A
    {
    public:
      void f (int i);
      void g (int j = 0);
    };
    inline void A::f (int i) { ... }
    bool operator == (A const & a1, A const & a2);
    #endif

And a source file:

    // A.cpp
    #include "A.h"
    void A::g (int j) { ... }
    bool operator == (A const & a1, A const & a2) { ... }

这篇关于将C ++方法声明从.hh移动到.cc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆