术语“游离功能”的含义是什么,在C ++? [英] What is the meaning of the term "free function" in C++?

查看:186
本文介绍了术语“游离功能”的含义是什么,在C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读boost :: test的文档时,我遇到了自由功能一词。我的理解是,一个自由函数是任何函数不返回任何东西(它的返回类型是void)。但是进一步阅读后,似乎自由函数也不接受任何参数。但我不确定。这些都是我的假设。因此,任何人都可以定义自由函数?

While reading the documentation for boost::test, I came across the term "free function". What I understand is that a free function is any function that doesn't return anything (Its return type is void). But after reading further it seems that free functions also don't take any arguments. But I am not sure. These all are my assumptions. So could anybody define free function?

推荐答案

C ++中的自由函数成员函数。每个不是成员函数的函数都是自由函数。

The term free function in C++ simply refers to non-member functions. Every function that is not a member function is a free function.

struct X {
    void f() {}               // not a free function
};
void g() {}                   // free function
int h(int, int) { return 1; } // also a free function

这篇关于术语“游离功能”的含义是什么,在C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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