如何在* .cpp文件中实现静态类成员函数? [英] How to implement static class member functions in *.cpp file?

查看:417
本文介绍了如何在* .cpp文件中实现静态类成员函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在* .cpp文件中实现 static 类成员函数,而不是在头文件中执行

Is it possible to implement static class member functions in *.cpp file instead of doing it in the header file ?

所有 static 函数总是 inline

推荐答案

它是。

test.hpp:

class A {
public:
    static int a(int i);
};

test.cpp:

#include <iostream>
#include "test.hpp"


int A::a(int i) {
    return i + 2;
}

using namespace std;
int main() {
    cout << A::a(4) << endl;
}

它们不总是内联的,没有,但编译器可以使它们。

They're not always inline, no, but the compiler can make them.

这篇关于如何在* .cpp文件中实现静态类成员函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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