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. atlassian-jira部署文档

    部署mysql数据库,我这里使用mariadb数据库,并且创建jira的数据库和用户,下面是创建jira数据库和用户的操作,安装数据库mysq过程略.(MYSQL数据库也是可以的,不过mysql的驱动 ...

  2. api跨域

    1.找方法名称是get开头的2.找get请求类型的 自定义webapi的路由规则,控制到action 1.跨域设置:(服务端)webconfig文件中,system.webServer节点下添加 &l ...

  3. python学习day15 模块(重点)

    模块(重点) python2,与py3的区别 py2:range() 在内存中立即把所有的值都创建,xrange() 不会再内存中立即创建,而是在循环时边环边创建. py3:range() 不会再内存 ...

  4. Unity下载

    Unity下载 Mac OS或Windows操作系统都可以使用对应的Unity版本进行开发 Unity引擎的官方网站:http://www.unity3d.com 官方下载地址:http://unit ...

  5. [BZOJ 4152][AMPPZ 2014]The Captain

    这道题对费用的规定是min(|x1-x2|,|y1-y2|).如果暴力枚举所有的点复杂度O(n²),n <= 200000,显然爆炸.于是我们要考虑加“有效边”,一个显然的事实是对于两个点,如果 ...

  6. python爬虫实例项目大全

    WechatSogou [1]- 微信公众号爬虫.基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫,返回结果是列表,每一项均是公众号具体信息字典. DouBanSpider [2]- ...

  7. Supervisor的安装以及使用

    1.supervisor的介绍 Supervisor 是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统,通过配置可以实 ...

  8. 移动端底部fixed固定定位输入框ios下不兼容

    简短记录下最近开发移动端项目碰到的小坑,产品需求做一个售后对话页面,底部固定输入框,和微信对话差不多,但是在ios下,fixed失效,输入框被虚拟键盘挡住,在安卓下是正常的. 尝试过网上说的很多方法, ...

  9. react项目构建

    1.react脚手架 npm install -g create-react-app create-react-app myproject 2.页面配置(bootcdn) <script src ...

  10. Web项目容器集成ActiveMQ & SpringBoot整合ActiveMQ

    集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ. 1.web项目中Broker启动的方式进行集成 在这里采用Liste ...