C ++:避免只有空(de)构造函数的.cpp文件 [英] C++: Avoid .cpp files with only an empty (de)constructor
本文介绍了C ++:避免只有空(de)构造函数的.cpp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我有这样的头文件时:
When I have a header file like this:
#ifndef GAMEVIEW_H_
#define GAMEVIEW_H_
#include <SDL/SDL.h>
class GameView
{
public:
GameView();
virtual ~GameView();
virtual void Update() = 0;
virtual void Render(SDL_Surface* buffer) = 0;
};
#endif /* GAMEVIEW_H_ */
我需要创建一个.cpp
文件,如下所示:
I need to create a .cpp
file like this:
#include "GameView.h"
GameView::~GameView()
{
}
GameView::GameView()
{
}
这有点愚蠢.只是一个.cpp文件,用于一个空的构造函数和反构造函数. 我只想在头文件中实现该方法.那要干净得多.
This is a bit stupid. Just a .cpp file for an empty constructor and deconstructor. I want to implement that method simply in the header file. That is much cleaner.
该怎么做?
推荐答案
您可以定义构造函数和 destructor (这是适当的术语,请使用它代替 deconstructor )内联:
You can define your constructor and destructor (this is the proper term, use this instead of deconstructor) inline:
class GameView
{
public:
GameView() {}
virtual ~GameView() {}
virtual void Update() = 0;
virtual void Render(SDL_Surface* buffer) = 0;
};
这篇关于C ++:避免只有空(de)构造函数的.cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文