- 论坛徽章:
- 0
|
- // ----------------------------------------------------------------------- Test.h
- #include <iostream>
- class Test
- {
- public:
- Test();
- ~Test();
-
- // 写在这里不会报“multiple definition of”
- void test1(void)
- {
- std:: cout << "test1" << endl;
- }
-
- void test2(void);
-
- void test3(void);
- };
- // 如果写Test.h的这里就会报“multiple definition of”
- void Test::test2(void)
- {
- std:: cout << "test2" << endl;
- }
- // 加了inline关键字的函数就不会报“multiple definition of”
- inline void Test::test3(void)
- {
- std:: cout << "test3" << endl;
- }
复制代码- // ----------------------------------------------------------------------- Main.cpp
- #include "Test.h"
- int main(void)
- {
- Test t;
- t.testMethod();
- return 0;
- }
复制代码
直接在类声明中定义的test1是不是内联函数?不管代码块多大总是内联?
为什么test1(), test2()不会被提示multiple definition of,而test3()会被提示? |
|