Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > 'inline' during declaration & definition

Reply
Thread Tools

'inline' during declaration & definition

 
 
qazmlp
Guest
Posts: n/a
 
      07-30-2003
// test.h
class test
{
public :
inline void check() ;

} ;

// test.C
inline void test::check() // Is 'inline' optional here?
{

}


Do I need to use 'inline' keyword again in the prototype in .C file
when it is already given as 'inline' in the .h file?.
 
Reply With Quote
 
 
 
 
ES Kim
Guest
Posts: n/a
 
      07-30-2003
"qazmlp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> // test.h
> class test
> {
> public :
> inline void check() ;
>
> } ;
>
> // test.C
> inline void test::check() // Is 'inline' optional here?
> {
>
> }
>
>
> Do I need to use 'inline' keyword again in the prototype in .C file
> when it is already given as 'inline' in the .h file?.


No, you don't have to, but definition of the inline function should be
known in the source file where it is called so that the function body
can be inserted in hard-coded way. A common practice is to define
the function in class definition block of header file. That way, all the
sources including the header will know the definition of the function.
It's just "in a line" anyway.

class test
{
public:
void check() { /* do something */ } // inline keyword is not necessary
};

--
ES Kim



 
Reply With Quote
 
 
 
 
Greg Comeau
Guest
Posts: n/a
 
      07-30-2003
In article <(E-Mail Removed) >,
qazmlp <(E-Mail Removed)> wrote:
>// test.h
>class test
>{
> public :
> inline void check() ;
>
>} ;
>
>// test.C
>inline void test::check() // Is 'inline' optional here?
>{
>
>}
>
>
>Do I need to use 'inline' keyword again in the prototype in .C file
>when it is already given as 'inline' in the .h file?.


It's up to you.

But:
Normally you wouldn't use inline in the prototype in a .C file
because normally your inline would be in a .h file.

Also, adding inline to a definition to a function that is only
provided in a non-.h file and is expect to be used by other
non-.h source files usually will not obtain inline'ability,
since many compilers do not yet support cross translation
inlining. IOWs, this:

// file1.cpp

// ....
void inline foo()
{
...
}



//file2.cpp

//...
void bar()
{
foo();
}

will usually not consider foo as a candidate for inlineing.
--
Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time template list definition / Run-time variable type definition Pierre Yves C++ 2 01-10-2008 02:52 PM
Automagic determination of definition based on definition location. Jon Slaughter C++ 4 10-26-2005 05:00 PM
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM
XML jargon: declaration vs. definition Razvan XML 4 02-10-2005 07:26 AM
help?: incomplete definition with complete definition in scope Ark C Programming 1 08-07-2004 04:21 PM



Advertisments