0

The following function declaration:

void Foo:DoSomething( ULONG &Count = 0) { .... }

Results in the following compile time error

error C2440: default argument cannot convert from 'int' to 'ULONG &'

What is the correct way of creating the signature so that when there is no parameter provided for Count its value will be zero.

pondigi
  • 856
  • 2
  • 8
  • 14

2 Answers2

2

You're taking a non-const reference to Count, so it can't be assigned by default with r-value.

Use

void Foo:DoSomething( const ULONG &Count = 0) { .... }

void Foo:DoSomething( ULONG Count = 0) { .... }

Stas
  • 11,571
  • 9
  • 40
  • 58
1

You can't do this for non-const references. A reference is pointing to an address in memory. Unless you specifically need reference semantics, I'd recommend just passing by value.

Thomas Nelson
  • 693
  • 5
  • 17