473,796 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10120
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<cla ss 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<cla ss 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
2699
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> using namespace std; template<class T, int size = 50> class Stack {
2
2015
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 I decided to try it on some code I'm writing. The idea is to use template objects to perform what happens in traditional nested for() loops. for(int row = 0; row < num_rows; row++) { for(int col = 0; col < num_cols; col++) {
3
1628
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 MyMethod ( /* ... */ ); // ...
6
4009
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 as well. To support thin-template, I need to make virtual function as inline. Now, I know that compiler would generate an out-of-line copy when it
5
2057
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 some investigating, I narrowed this down to a very odd behavior (bug?) of the VC++.NET 2003 compiler: If a class that is declared as __declspec(dllimport) derives from a template, that template's methods are never inlined, even if declared with...
11
2330
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 always expanded inline. Recently, I replaced an explicitly written function with one implemented using templates (and partial-template specialisation), in the belief that the the latter would be entirely inlined-away by the compiler, leaving the
25
3339
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 same subject in clc++m to get the more of the context. Ted
28
2642
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 executable size. This should not cause any performance issue. So, is it safe to say that if I can offered to have bigger image size I can go ahead and use Templates with out worrying about any other issues?
5
2667
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 std;
5
5062
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. ] $ g++ main.cpp foo.cpp /home/klaas/tmp/cciAcYgl.o: In function `main':
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.