By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

'inline' during declaration & definition

P: n/a
// 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?.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"qazmlp" <qa********@rediffmail.com> wrote in message
news:db**************************@posting.google.c 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

Jul 19 '05 #2

P: n/a
In article <db**************************@posting.google.com >,
qazmlp <qa********@rediffmail.com> 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?
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.