473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

templates and inline

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
2 10077
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Senthilraja | last post by:
I have the following program using templates. Someone please let me know the syntax to be used for defining the member functions push, pop etc. as non-inline functions. #include <iostream>...
2
by: Steven T. Hatton | last post by:
While thunbing through _C++ Templates, The Complete Guide_ (reckon I aught to read it?) I came across a discussion of using templates to "unroll" loops. I thought that looked like a good idea, so...
3
by: Ruben Campos | last post by:
I've found a problem with types defined inside a template. With a non-template class, I can write the following: // MyClass.hpp class MyClass { // ... typedef unsigned int MyType; MyType...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
5
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After...
11
by: Elpoca | last post by:
Hi: What rules govern the inlining of templated functions and templated class methods? It has always been my understanding that both templated functions and templated class methods were...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
5
by: Mark | last post by:
Sorry for creating such a newbish topic, but I just can't seem to figure out what the problem is here. // main.cpp #include <cstdlib> #include <iostream> #include "Vector.h" using namespace...
5
by: ciccio | last post by:
Hi, I have a problem with my code that the compiler does not find any inline functions which are static. The simple code example is written below, this is what the compiler throws at me. ]...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.