开发者

is it possible to define the static member function of a class in .cpp file instead of its header file?

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 开发者_StackOverflowshould i do? for that.


Like you do for normal functions:

FooBar.h

#ifndef FOOBAR_H
#define FOOBAR_H


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

#endif

FooBar.cpp

#include "FooBar.h"

void FooBar::test()
{

}


If using linux

static pthread_once_t semaphore = PTHREAD_ONCE_INIT;
pthread_once( & semaphore, FooBar::test() );

So you can be sure to go once in your function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜