Do inline functions support seperate compilation?

Do inline functions (including inline class member functions) support seperate compilation?

Do inline function definitions must be included inside the header file?
Inline function implementation can be done in the .cpp file when you explicitly suggest to the compiler to inline.

Aceix.
But I got a compile time error:


error LNK2019: unresolved external symbol "void __cdecl func(void)" (?func@@YAXXZ) referenced in function _main
1>E:\Andy\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: 1 unresolved externals


1
2
3
4
5
6
7
8
9
10
//header file

#ifndef HEADER_H
#define HEADER_H

#include <iostream>

inline void func();

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
//file1.cpp

#include <iostream>
#include "Header.h"

using namespace std;

int main() {
	
	func();

	cin.get();

}



1
2
3
4
5
6
7
8
//file2.cpp

#include "Header.h"
#include <iostream>

inline void func() {
	std::cout << "hoho";
}
An inline function needs to be defined in every translation unit in which it is used.
Place the definition of the inline function in the header file.
Does it mean that inline functions are internal linkage like const variables?
> Does it mean that inline functions are internal linkage like const variables?

No. By default, inline functions have external linkage. However,

An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case. ...

An inline function with external linkage shall have the same address in all translation units.
A static local variable in an extern inline function always refers to the same object.
A string literal in the body of an extern inline function is the same object in different translation units. - IS
Topic archived. No new replies allowed.