是否可以在.cpp文件而不是其头文件中定义类的静态成员函数? [英] is it possible to define the static member function of a class in .cpp file instead of its header file?

查看:925
本文介绍了是否可以在.cpp文件而不是其头文件中定义类的静态成员函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,应该只运行一次类的所有实例。我们认为使用静态函数调用方法。所有的Web示例显示,静态函数定义在Header文件(在类中)本身。我的功能是大的我无法定义在头文件中我该怎么办?

i am having a function which should be run only once for all instance of the class.i thought to use the static function calling method. all the web example shows that static function define in the Header file(inside the class) itself. my function is big one i cant define that in header file what should i do? for that.

推荐答案

与正常功能一样:

FooBar.h

#ifndef FOOBAR_H
#define FOOBAR_H


class FooBar
{
public:
    static void test();
};

#endif

FooBar.cpp

FooBar.cpp

#include "FooBar.h"

void FooBar::test()
{

}

这篇关于是否可以在.cpp文件而不是其头文件中定义类的静态成员函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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