why it doesn't popup multi definitions error for method in .h class for C++?

本文探讨了C++中关于单一定义规则(ODR)的应用案例。通过一个具体例子解释了为何同一个类的方法在不同源文件中包含时不会引发重复定义错误。文章深入浅出地分析了ODR的具体规定及其在实际编程中的体现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@jiafu: 3.2/4 (about the One definition Rule); "Every program shall contain exactly one definition of everynon-inline function or variable that is odr-used in that program; no diagnostic required". And 9.3./2: "A member function may be defined (8.4) in its class definition, in which case it is an inline member function (7.1.2), [...]




there is one class.h object with method test() which has detailed execute content。

class Object{

   void test(){
           cout<<"do test"<<endl;
   }
}

thus cpp1 include the Object.h and cpp2 included it two, why it doesn't popup multiple definition error when linking cpp1 and cpp2?


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值