473,508 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting default value for a parameter of a class member function

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?

Jul 23 '05 #1
4 1465


bl**********@gmail.com wrote:
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

Jul 23 '05 #2

<bl**********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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

Jul 23 '05 #3
bl**********@gmail.com wrote:
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.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #4
I actually rather throw exception in case user enters size<0.

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
12680
by: earl | last post by:
class temp { public: temp(); foo(char, char, char*); private: char matrix; }; temp::foo(char p, char o, char m = matrix )
16
2527
by: Steven T. Hatton | last post by:
As far as I know, there is no way to provide a default value for the argument to the constructor A::A(char (&array)) in this example. Correct? struct A{ A(char (&array) ){...
8
1490
by: pauldepstein | last post by:
I am writing a program which looks at nodes which have coordinates which are time-dependent. So I have a class called node which contains the private member declarations int date; int month; ...
9
5781
by: Peter Oliphant | last post by:
I've been told that value structs can have default constructors (I'm using VS C++.NET 2005 PRO using clr:/pure syntax). But the following code generates the following error: value struct...
22
2398
by: sujilc | last post by:
This question seems to be silly. Can ony one figure out the default functions implemented by compiler when we decalre a class like class A { } According to me this declaration will define...
1
6441
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
1980
by: Osama Aouda | last post by:
Hi All, If you have the following class: class foo { private: int offset; public: void SetOffset(int InOffset); };
4
2369
by: tutmann | last post by:
Hello, to make it short, why does this not compile? class B { public: int b(void) { return 1;} } void f( B x, int i = x.b()) { }
12
2301
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
4
3003
by: David Sanders | last post by:
Hi, I have a class with an integer template parameter, taking values 1, 2 or 3, and a function 'calc' in that class which performs calculations. Some calculations need only be performed if the...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.