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. YUI Compressor

    简介 根据雅虎卓越性能团队的说法,40%到60%的雅虎用户拥有空闲缓存体验,所有页面浏览量中约有20%是使用空缓存完成的(请参阅Tenni Theurer在YUIBlog上的这篇文章)有关浏览器缓存使 ...

  2. codeblocks(其它软件)修改后缀文件的打开默认方式

  3. python3 动态import

    有些情况下,需要动态的替换引入的包 1.常用的import方法 import platform import os 2.__import__ 动态引用 loop_manager = __import_ ...

  4. Angular记录(10)

    文档资料 速查表:https://www.angular.cn/guide/cheatsheet 风格指南:https://www.angular.cn/guide/styleguide Angula ...

  5. ubuntu18系统美化

    1. 将选定的背景图片 login-bg.jpg 移动到 /usr/share/backgrounds/ 目录下 sudo mv currentdir/mypicture.jpg /usr/share ...

  6. SQL Server 游标的使用示例

    Ø  简介 本文主要记录 MSSQL 中的游标使用示例,在有必要时方便借鉴查阅.游标一般定义在某段功能性的 SQL 语句中,或者存储过程中.之所以选择用它,是因为有时候无法使用简单的 SQL 语句满足 ...

  7. P1074 靶形数独题解

    题目描述 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向 Z 博士请教,Z 博士拿出了他最近发明的“靶 ...

  8. QMQTT简单介绍(1)

    1 准备工具: wireshark安装包:网络抓包工具qmqtt源码:mqtt客户端源码(Qt版本)官网:http://mqtt.org/英文版协议说明文档:http://docs.oasis-ope ...

  9. js中的 Date对象 在 IOS 手机中的兼容性问题

    项目中有个时间相关的需求,很自然的用到了 js 中的 new Date() 获取时间,浏览器使用模拟手机模式访问没有问题,但是真机测试时发现,ios系统的手机无法显示时间. 定位问题发现是 new D ...

  10. L1-Day9

    1.学习让我感觉很棒.(什么关系?动作 or 描述?主语部分是?)         [我的翻译]Learning makes me that feel good.         [标准答案]Lear ...