again inline

P

puzzlecracker

why do we need to define the inline function if it is included in (.h)
- why can't its definition reside somewhere else, with (.h) having
only its prototype?
 
I

Ioannis Vranos

puzzlecracker said:
why do we need to define the inline function if it is included in (.h)
- why can't its definition reside somewhere else, with (.h) having
only its prototype?


The definition of an inline function must exist in any compilation unit
(file) that it is used and not its declaration only, and these
definitions of the function must all be the same.


So the usual approach is to place its definition in a header file and
#include it wherever we use that function.
 
E

E. Robert Tisdale

puzzlecracker said:
Why do we need to define the inline function if it is included in (.h)
Why can't its definition reside somewhere else
with (.h) having only its prototype?

Probably just to simplify implementations.
If you kept inline function definitions somewhere else --
in a repository for example --
you would need a way to tell your compiler
where to look for the repository.

This is a problem for function template definitions
because the ANSI/ISO C++ does not (and probably can't)
specify how function template definitions
are archived and found.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top