Problem with default function argument on linux

N

none

In a template class I declare a function:

bool LoadFile(std::string filename, bool multi=false, bool endian=false);

and in the .cpp file I define it:


template< typename M, unsigned int Dimension>
bool
MyTestClass<M,Dimension>::LoadFile(std::string filename, bool multi = false, bool endian = false) {

....

}


But when I compile I get the error:

error: default argument given for parameter 3 of ‘bool MyTestClass<M,
Dimension>::LoadFile(std::string, bool, bool)’


It compiles fine on windows with visual studio 2008, but why does it not compile on linux?
 
N

none

none said:
In a template class I declare a function:

bool LoadFile(std::string filename, bool multi=false, bool endian=false);

and in the .cpp file I define it:


template< typename M, unsigned int Dimension>
bool
MyTestClass<M,Dimension>::LoadFile(std::string filename, bool multi =
false, bool endian = false) {

...

}


But when I compile I get the error:

error: default argument given for parameter 3 of ‘bool MyTestClass<M,
Dimension>::LoadFile(std::string, bool, bool)’


It compiles fine on windows with visual studio 2008, but why does it not
compile on linux?

Arg default values should only be specified in the declaration, problem solved.
 
S

Saeed Amrollahi

In a template class I declare a function:

   bool LoadFile(std::string filename, bool multi=false, bool endian=false);

and in the .cpp file I define it:

template< typename M, unsigned int Dimension>
bool
MyTestClass<M,Dimension>::LoadFile(std::string filename, bool multi = false, bool endian = false) {

...

}

But when I compile I get the error:

error: default argument given for parameter 3 of ‘bool MyTestClass<M,
Dimension>::LoadFile(std::string, bool, bool)’

It compiles fine on windows with visual studio 2008, but why does it not compile on linux?

Hi

I believe, it is a general rule:
The default argument should be specified for a parameter in either
declaration or definition.

My two cents

Regards,
-- Saeed Amrollahi
 
S

Saeed Amrollahi

In a template class I declare a function:

   bool LoadFile(std::string filename, bool multi=false, bool endian=false);

and in the .cpp file I define it:

template< typename M, unsigned int Dimension>
bool
MyTestClass<M,Dimension>::LoadFile(std::string filename, bool multi = false, bool endian = false) {

...

}

But when I compile I get the error:

error: default argument given for parameter 3 of ‘bool MyTestClass<M,
Dimension>::LoadFile(std::string, bool, bool)’

It compiles fine on windows with visual studio 2008, but why does it not compile on linux?

Hi
I believe, it is a general rule:
The default argument should be specified in either function
declaration or function definition.

My two cents,
-- Saeed Amrollahi
 
I

Ian Collins

Hi

I believe, it is a general rule:
The default argument should be specified for a parameter in either
declaration or definition.

Only in the definition if it is also the declaration.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top