About why inline member function should defined in the header file.

It is legal to specify inline on both the declaration and the definition. But the keyword inline must be placed with the function definition body to make the function inline. Just putting inline in front of function declaration has no effect.

So inline member functions should be declared and defined in the same header. In other words, the inline function should (not must) be placed in the header file instead of the cpp file. An identical definition for the function must exist in every translation unit that uses that line function because one definition rule for inline functions. Otherwise, the compiler will report an error(LINK2019 unsolved external symbol) because the compiler must be able to see the same function define for every call. So. .yes, if you use an inline function in only a cpp file and no others will call it, you can put function define in that cpp file and then successfully pass compilation. If you accidentally call it in another file, the compiler will throw an error.

And the same time, inline member function declared outside the class in the header must be marked inline because otherwise, every translation unit which includes the header will contain a definition of the function, and the linker will complain about multiple definitions. As mentioned above, one definition rule.

About Why Inline Member Function Should Defined in The Header File的更多相关文章

  1. Thinkphp---------Call to a member function free_result() on a non-object

    1.平时用框架用久了,直接执行原生的sql反而做起来反应迟钝了.今天遇到一个问题,就是直接执行一个添加的sql语句,然后我用了TP框架的M()->query();方法.运行以后,会报Call t ...

  2. :( Call to a member function Table() on a non-object 错误位置

    :( Call to a member function Table() on a non-object 错误位置 $Model不是模板,是你自己先前链接数据库返回的对象...我的是改为$Form

  3. Fatal error: Call to a member function bind_param() on a non-object in

    今天在练习 mysql是出现错误:   Fatal error: Call to a member function bind_param() on a non-object in 解决步骤: 1. ...

  4. ECmall错误:Call to a member function get_users_count() on a non-object

    问题描述: 在后台添加了一个app报错:Call to a member function get_users_count()Fatal error: Call to a member functio ...

  5. magento后台 Fatal error: Call to a member function getId() on a non-object in错误

    后台分类管理出现错误 Fatal error: Call to a member function getId() on a non-object in 在数据库中运行以下sql语句 INSERT I ...

  6. Function语义学之member function

    之前我们讲过编译器会对 nonmember functions 进行怎样的扩充和该写,今天我们来讲一下 member functions 函数调用方式 一.Nonstatic Member Funct ...

  7. Timer.4 - Using a member function as a handler

    In this tutorial we will see how to use a class member function as a callback handler. The program s ...

  8. C++ - 模板类模板成员函数(member function template)隐式处理(implicit)变化

    模板类模板成员函数(member function template)隐式处理(implicit)变化 本文地址: http://blog.csdn.net/caroline_wendy/articl ...

  9. About The Order of The Declarations And Definition When Making a Member Function a Friend.关于使类成员成为另一个类友元函数的声明顺序和定义。

    If only member function clear of WindowMgr is a friend of Screen, there are some points need to note ...

随机推荐

  1. CF1157B-Long Number题解

    原题地址 题目大意:有一个\(n\)位数,其中的数字只有\(1\)~\(9\),不包括\(0\),每个\(1\)~\(9\)的数字有一个映射,映射也在\(1\)~\(9\)中,现在我们可以对这个\(n ...

  2. win 10 dpi:150% 与 win 7 dpi:150% 的不同之处

    由于 win 7 和 win 10 的 dpi 处理方式不同,导致我们写的客户端程序在 win 7 上运行正常,在 win 10(dpi:150%)上运行不正常了. 具体的描述,可参考:解决win10 ...

  3. 51nod 1630(定积分 + 期望)

    51nod1630 每个人进入竞技场后,会等概率随机匹配一个人,匹配到的人与当前胜利和失败场数无关. 胜利达到x场,或失败达到y场后,退出竞技场,根据退出时的胜利场数获得奖励,不能中途放弃. 水平高的 ...

  4. CDN-常用静态资源公共库

    js.css 等静态资源可以放在自己的服务器上,或者引用网络上的公共库使用(CDN) CDN 读取失败时从本地加载 <script src="https://code.jquery.c ...

  5. 多个div实现随意拖拽功能

    鼠标事件 mousedownmousemovemouseup注意事项:被拖动的div的position属性值一定是absolute.切记不可使用margin-top:10px;而应该使用top:10p ...

  6. Hper-V卸载

    1.txt文件输入以下内容,后缀改为cmd,以管理员身份执行 mountvol X: /s copy %WINDIR%\System32\SecConfig.efi X:\EFI\Microsoft\ ...

  7. L1-Day13

    1.Being late is an unforgivable sin here.[我的翻译]在北京,迟到是不可饶恕的罪名.[标准答案]在这里迟到是不可原谅的.[对比分析]对自己的也是醉醉的了,Bei ...

  8. json基础小结

    定义:json是一种前后端数据传送的格式规定json对象,json字符串 (区别 json字符串是有json格式的字符串)1.创建(两中json结构,一种是对象,一种是数组)json对象:var ao ...

  9. 学习itop4412开发板有哪些资料可学习?能否学会

    1.光盘资料 下面简单的做一下了解,在需要使用这些资料的时候,会针对性的做详细介绍. 将文件以及文件夹按照“名称+递增”的方式排列,如下: 01_PCB_SCH_DATASHEET-- -----开发 ...

  10. Python爬虫从入门到进阶(3)之requests的使用

    快速上手(官网地址:http://www.python-requests.org/en/master/user/quickstart/) 发送请求 首先导入Requests模块 import requ ...