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

templates and inline

P: n/a
The common method of defining template classes and functions is to put the
definition and declaration into the same header file. Or at least I believe
it to be the common method and it is certainly the one I use.

This leaves me with a question.

As example, consider the following class.

template<class T>
class foo
{
public:
void my_big_func()
{
// non trivial code goes here that is something you wouldnt want
// to be inline
}
};
Now my question is, since all class functions declared and defined within
the class declaration are taken to be inline, does that mean all my template
class functions will be inline? If so how can I prevent this? and how can
I make the ones I want to be inline be inline.

My thought is I can not declare my template class memebers within the class
declaration, but this is extremely tedious and hard to maintain.

Jeff
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 07 Aug 2003 12:23:55 GMT, "Jeff Williams" <no*********************************@mfchelp.com > wrote:
The common method of defining template classes and functions is to put the
definition and declaration into the same header file. Or at least I believe
it to be the common method and it is certainly the one I use.

This leaves me with a question.

As example, consider the following class.

template<class T>
class foo
{
public:
void my_big_func()
{
// non trivial code goes here that is something you wouldnt want
// to be inline
}
};
Now my question is, since all class functions declared and defined within
the class declaration are taken to be inline, does that mean all my template
class functions will be inline?
They're textually inline but not declared 'inline', and may or may not be
inlined in the compiled program, at the compiler's discretion.
... how can I make the ones I want to be inline be inline.


You cannot, but you can give the compiler a hint via 'inline'.

Jul 19 '05 #2

P: n/a
On Thu, 07 Aug 2003 12:23:55 GMT, "Jeff Williams"
<no*********************************@mfchelp.com > wrote:
The common method of defining template classes and functions is to put the
definition and declaration into the same header file. Or at least I believe
it to be the common method and it is certainly the one I use.

This leaves me with a question.

As example, consider the following class.

template<class T>
class foo
{
public:
void my_big_func()
{
// non trivial code goes here that is something you wouldnt want
// to be inline
}
};
Now my question is, since all class functions declared and defined within
the class declaration are taken to be inline, does that mean all my template
class functions will be inline? If so how can I prevent this? and how can
I make the ones I want to be inline be inline.
Define the members outside the class definition, and use inline when
you want inline. Some compilers think (or know) that they know better,
and might ignore the use of inline, and not inline or inline at their
own discretion.
My thought is I can not declare my template class memebers within the class
declaration, but this is extremely tedious and hard to maintain.


You have to declare them in the class in C++, but you can define them
outside. You can't call that hard to maintain, unless you always
define all your methods inside the class definition for non-templates
too!

Tom
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.