[Dev-C++] Is it possible - templates (.h and .cpp) ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Carla M. W. <ca...@lr...> - 2004-04-27 16:50:41
|
Hello,
Is it possible to have a template, with prototypes of functions present in
.h (header files) and implementation of these functions being implemented
in .cpp files ?
Somebody has tested this situation yet ??
Thanks, Carla.
Example:
// test.h
#ifndef TEST
#define TEST
template <class T>
T max ( T a, T b, T c);
#endif
// test.cpp
#include "test.h"
template <class T>
T max (T a, T b, T c) {
if ((a>b) && (a>c))
return a;
if ((b>a) && (b>c))
return b;
else
return c;
}
// main.cpp
#include <iostream.h>
#include "test.h"
int main() {
int v1, v2, v3;
cin >> v1 >> v2 >> v3;
cout << max(v1, v2, v3);
return 0;
}
|