setting default value for a parameter of a class member function

B

bluekite2000

I have
class Foo
{
....
....
//copy constructor
Foo(const Foo<T>& F, int size=F.size())
{
...
...
}

and get this error
error: `F' was not declared in this scope

Any solution to this?
 
D

Dan Cernat

I have
class Foo
{
...
...
//copy constructor
Foo(const Foo<T>& F, int size=F.size())
{
..
..
}

and get this error
error: `F' was not declared in this scope

Any solution to this?

Foo(const Foo<T>& F)
{
int size = F.size();
.....
}

or, if you really need two arguments:
Foo(const Foo<T>& F, int size=-1)
{
if (size < 0)
size = F.size();
....
}

Dan
 
H

Howard

I have
class Foo
{
...
...
//copy constructor
Foo(const Foo<T>& F, int size=F.size())
{
..
..
}

and get this error
error: `F' was not declared in this scope

Any solution to this?

I'm not sure if there's a *neat* solution to that, but I've got *a*
solution...

I'd guess that size can't be negative, right? How about:

Foo( const Foo<T>& F, int size = -1)
{
if (size < 0)
size = F.size();
...
}

Would that work for you?

-Howard
 
P

Pete Becker

I have
class Foo
{
...
...
//copy constructor
Foo(const Foo<T>& F, int size=F.size())
{
..
..
}

and get this error
error: `F' was not declared in this scope

Any solution to this?

Write two constructors.
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top