0

It is possible to write, but the compiler dont find the function when I want to use func(x):

template <class T>
double func(const double& x, const double& error = 0)
{...}

I have to write separately, like this why?

template <class T>
double func(const double& x, const double& error)
{...}

template <class T>
double func(const double& x)
{double error = 0; ...}
4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Dave Sinkula
0

It is possible to write, but the compiler dont find the function when I want to use func(x):

template <class T>
double func(const double& x, const double& error = 0)
{...}

Reference to ... what? NULL?

Are you passing by reference when you don't need to? Are you using T anywhere?

template <class T>
double func(const T &x, double error = 0)
{
   // ...
   return x;
}

int main(){
   double a = 1.0 / 3.0, err = 5;
   func(a,err);
}

??

Edited by Dave Sinkula: n/a

0

Instead of const double& error = 0 you could code it as const double* error = NULL . References can not be NULL, but pointers can.

1

but you cannaot call func(a), can you?

Simply giving it a try would have gotten you an answer much quicker.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.