Separating template implementation from declaration


 
Thread Tools Search this Thread
Top Forums Programming Separating template implementation from declaration
# 1  
Old 02-12-2013
Separating template implementation from declaration

I am separating the template implementation from the declaration in the way described below.

When coding the implementation, is it a good idea to have the two code sections

Code:
#ifndef TESTTEMP_IPP
#define TESTTEMP_IPP

and

Code:
#include "TestTemp.hpp"

Files are as follows

Code:
// TestTemp.hpp

#ifndef TESTTEMP_HPP
#define_TESTTEMP_HPP

template<class T>
class TestTemp
{

public:

   TestTemp();
   void SetValue( T obj_i );
    T Getalue();

private:

   T m_Obj;

};

#include "TestTemp.ipp"

#endif

Code:
// TestTemp.ipp

#ifndef TESTTEMP_IPP
#define TESTTEMP_IPP

#include "TestTemp.hpp"
  
template <class T>
TestTemp<T>::TestTemp()
{}

template <class T>
void TestTemp<T>::SetValue( T obj_i )
{} 

template <class T>
T TestTemp<T>::Getalue()
{
return m_Obj;
}

#endif


Last edited by kristinu; 02-12-2013 at 03:30 PM..
# 2  
Old 02-12-2013
include infinite loop?
# 3  
Old 02-12-2013
Quote:
Originally Posted by DGPickett
include infinite loop?
Meaning I remove

Code:
#include "TestTemp.hpp"

from the .ipp.

Correct?
# 4  
Old 02-12-2013
# 5  
Old 02-12-2013
My plan is to have

Code:
#include "TestTemp.ipp"

in the the .hpp

So I will remove the include from the ipp.

---------- Post updated at 03:28 PM ---------- Previous update was at 03:25 PM ----------

Yes, my plan was to have things similar to what is done in boost.
# 6  
Old 02-12-2013
Good luck! Templates are cool! I use RogueWave here, a bit richer than STL.
# 7  
Old 02-13-2013
There is another question. I have a class called Layer separated in 3 files

layer.hpp declaration
layer.ipp template implementations and inline functions
layer.cpp all remaining implementations

My question is what include files need I put in ipp and cpp.
Currently this is what I have.

Code:
// layer.hpp

#ifndef LAYER_HPP
#define LAYER_HPP

#include <assert.h>
#include <stdarg.h>

#include "tomso/optparse/parsing.hpp"
#include "tomso/string/string.hpp"
#include "tomso/linear_algebra/vect2.hpp"
#include "tomso/linear_algebra/gauss_elim.hpp"
#include "tomso/raytrace/layint_linear.hpp"
#include "tomso/raytrace/layint_spline.hpp"
#include "tomso/raytrace/layint_trigon.hpp"

enum TWave {
  PWave,
  SWave
};

class Layer {

  protected:

    Vect2  Xi;        // Top left corner of sound speed model
    Vect2  Xf;        // Bottom right corner of sound speed model
    float  VSVP;    
    bool  PS;
    ...


Code:
// layer.ipp

#include <assert.h>
#include <stdarg.h>

#include "tomso/optparse/parsing.hpp"
#include "tomso/string/string.hpp"
#include "tomso/linear_algebra/vect2.hpp"
#include "tomso/linear_algebra/gauss_elim.hpp"
#include "tomso/raytrace/layint_linear.hpp"
#include "tomso/raytrace/layint_spline.hpp"
#include "tomso/raytrace/laymod_trigon.hpp"

inline Layer::Layer (
  const Vect2&  xi,
  const Vect2&  xf
) {

  Xi = xi;
  Xf = xf;
  VSVP = DefVSVP;
  PS = false;
  Int = NULL;

}

Code:
// layer.cpp

#include "tomso/raytrace/layer.hpp"

Layer::~Layer (
) {

  if (Int != NULL) {
    delete Int;
  }
  if (ModP != NULL) {
    delete ModP;
  }
  if (ModS != NULL) {
    delete ModS;
  }

}


Last edited by kristinu; 02-13-2013 at 07:43 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk RS declaration with \n

Hello Team, input text:... (7 Replies)
Discussion started by: chandana.hs
7 Replies

2. Shell Programming and Scripting

variable declaration

how to check 1. If variable is declared or not 2. If any value if assigned to variable or not. in UNIX shell script (6 Replies)
Discussion started by: ace_friends22
6 Replies

3. Programming

DIR declaration

are you suppose to only use one DIR declarations, for example DIR *dir_ptr; because I'm declaring mine like so: DIR *dir_ptr_src, *dir_ptr_dest; and using it like so: if( ( dir_ptr_src = opendir ( av ) ) != NULL && ( dir_ptr_dest = opendir( av ) ) != NULL ) /* check if... (3 Replies)
Discussion started by: l flipboi l
3 Replies

4. Shell Programming and Scripting

separating folders

I have folder like main. inside main folder there are subfolders & files like main1 main2 main3, file1, file2, file3. I want folders main1 & main2, file1, file2 from main folder. copy them into new folder. Please suggest me how to do it. I am new to shell programming (2 Replies)
Discussion started by: ypremcha
2 Replies

5. Shell Programming and Scripting

Separating fields

Hi, I have a text file in following format: 2.45 5.67 6.43 I have to cut the values before decimal and store them in a file. So the output file should look like: 2 5 6 . . and so on... Can someone suggest me a sed/awk command for doing this? (2 Replies)
Discussion started by: sajal.bhatia
2 Replies

6. Shell Programming and Scripting

variable declaration

Hi Guys, What does this mean actually ? Can somebody give me any explanation ? x=${x:=1} Thanks (2 Replies)
Discussion started by: amit.behera
2 Replies

7. Shell Programming and Scripting

Help with variable declaration

I declared a variable x that gets the count(*) from a table. The table name is also defined as a variable. What's wrong with this statment : X=” select count(*) from ${table_name}“ then y = `${X}${table_name}' echo ${y} It throws an error saying count not found. Please... (1 Reply)
Discussion started by: dsravan
1 Replies

8. Shell Programming and Scripting

separating fields

Hi, i have a file as follows: jonathan:bonus1,bonus2 gerald:bonus1 patrick:bonus1,bonus2 My desired output is jonathan:bonus1 jonathan:bonus2 gerald:bonus1 patrick:bonus1 patrick:bonus2 my current code is cat $F | awk -F"" how should i continue the code? Can i do something... (5 Replies)
Discussion started by: new2ss
5 Replies

9. Programming

separating commands

hey there well i have a small problem with my code. when for example : " /bin/sleep 10 & ls -l mila > xyz " is entered, the program is supposed to separate the two commands 1) /bin/sleep 10 & and 2) ls -l mila > xyz. im not sure of how to achieve this. my current program stores both commands... (2 Replies)
Discussion started by: mile1982
2 Replies

10. Programming

Variable declaration

what does this mean when a variable is declared as register int i; Thanks. :confused: (2 Replies)
Discussion started by: laila63
2 Replies
Login or Register to Ask a Question