#define + template

Dear all,

on top of my program I would like to define the applied data type to switch easily between double or single precision.

My code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define ftype double;  // double or float

main()
{

Tensor<ftype> density; 

func(&density);

}

void func(Tensor<ftype> *T)
{
...
}



However g++ come up with

1
2
3
 error: template argument 1 is invalid
 error: expected primary-expression before '>' token
 error: 'density' was not declared in this scope


What would be a right implementation of my "feature"? "ftype" can't be include in the "Tensor" definition, because sometimes I would like to create a "Tensor<int>"

Thanks a lot!

Preprocessor statements, like #define, do not have a semicolon (;) at the end of them. Your code is essentially translating to this:
Tensor<doube;> density;

I recommend using typedef instead:
typedef double ftype;
Last edited on
The correct way to do this is:
typedef double ftype;

edit: too slow.
Last edited on
And main should be declared to return an int ( int main() )
Topic archived. No new replies allowed.