Default value for template function arguments 
Author Message
 Default value for template function arguments

Hi there:

I've a problem with the code segment I attach below.  I can use it with
Borland C++ and G++ with minor adjustments.  But I cannot get the work
done with VC++.  Can somebody tell me what's wrong?

// header


#include <iostream.h>

template <class T>
class SimpleClass
  friend void SimpleFunction(const SimpleClass<T> & a, const T & b);

  SimpleClass(const T & a) : a_(a) {};

  T a_;


template <class T>
void SimpleFunction(const SimpleClass<T> & a, const T & b = T(0))
  cout << a.a_ - b;



// main function

#include "misc.h"

int main(int argc, char* argv[])
  SimpleClass<double> a(0.1);

  return 0;



The compiler gives following complaint:
xxxx.cpp(12) : error C2660: 'SimpleFunction' : function does not take 1

I really don't understand what's wrong.  Maybe I miss some keyword or
compile options.  Please advise me.

Thanks in advance.


Wed, 13 Jun 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Simple template function with default argument

2. Function Template has Default Arguments

3. template template parameter with default value (VS.NET 2003)

4. template-template params default values - std::deque

5. template arguments used within a template function - how?

6. explicit template arguments to function templates

7. Template Default argument lookup

8. Template argument dependant default parameter

9. Default template arguments

10. Default template arguments.

11. Default argument values

12. Can class type arguments have default values?


Powered by phpBB® Forum Software