Compiler Ignoring Default Arguments?

closed account (zb0S216C)
It seems as though my default argument for my function is being ignored by my compiler. It's quite confusing. Here's my function + definition:

Prototype: type_spec &acquire( const Index );

Note that Index is a type-defined unsigned int.

Definition:
1
2
3
4
5
template < typename type_spec >
type_spec &Group< type_spec >::acquire( const Index index = 0U )
{
    // Body omitted.
}


The default value for the index parameter is being ignored. The compiler says:

"error C2660: Group<type_spec>::acquire' : function does not take 0 arguments"

Ideas?

Wazzak
closed account (zb0S216C)
Never mind. It turns out that the prototype needs the default argument as well.

Wazzak
This is caused by the fact that C++ uses default arguments at the client side, instead of compiling them into the function body. This leads to some paradoxes like this:

1
2
3
4
5
6
7
8
9
10
class Base {
  virtual void print(lang: string = "C++") {  cout << lang << " rocks"; }
};

class Derived: public Base {
  virtual void print(lang: string = "PHP") {  cout << lang << " sucks"; }
};

Base* object = new Derived();
object->print();  // guess what it prints? 
Last edited on
Topic archived. No new replies allowed.