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. HF-01

    胡凡 本书在第2章对C语言的语法进行了详细的入门讲解,并在其中融入了部分C+的特性. 第3-5章是 入门部分. 第3章 初步训练读者最基本的编写代码能力: 第4章对 常用介绍,内容重要: 第5章是   ...

  2. Filebeat 日志收集器 安装和配置

    Filebeat的配置文件是/etc/filebeat/filebeat.yml,遵循YAML语法.具体可以配置如下几个项目: Filebeat Output Shipper Logging(可选) ...

  3. 【洛谷P1402】酒店之王

    题目大意:有三个集合 \(P,Q,N\),P 与 N 集合之间存在一些有向边,N 与 Q 集合之间存在一些有向边.在三个集合中每个点最多只能利用一次的前提下,求最多能利用多少N 集合中的点,使得 \( ...

  4. 第一周java学习总结

    学号 20175206 <Java程序设计>第一周学习总结 教材学习内容总结 第一章是关于JAVA入门的注意事项: 第一章主要按照顺序讲了JAVA的地位,诞生,特点,JDK的安装,一些ja ...

  5. Ansible-基础

    Ansible架构 Inventory   主机清单,可以对主机分组 ansible-hoc   ansible的命令,适用临时场景 ansible-playbook   ansible是一个场景的集 ...

  6. 【JS】前端文件下载(无刷新)方法总结

    #传统方法 利用iframe 或 form.submit 或 windows.open直接向后端发请求,后端返回文件流,后端处理成功后会直接返回到页面,浏览器会整理并打开自己的保存下载文件机制 . 1 ...

  7. 源码-mybatis-01-SqlSessionFactory创建

    0.总概   1.SqlSessionFactory在mybatis只要创建一次: import com.suntek.vdm.gw.util.AESEncipher; import org.apac ...

  8. 使用fork的str_cli函数

    void str_cli(FILE *fp, int sockfd) { pid_t pid; char sendline[MAXLINE], recvline[MAXLINE]; ) { /* ch ...

  9. hibernate自定义校验Valid

    步骤: 1.定义注解: import javax.validation.Constraint; import javax.validation.Payload; import java.lang.an ...

  10. 题解 P3871 【[TJOI2010]中位数】

    orz各位大佬,题解太强了,主席树,堆,线段树,splay,还有暴力,太巨了.所以我用的是fhq treap(好像更高级).算了. 反正都是平衡树,这道题就是动态求中位数,不会做的同学可以先做弱化版P ...