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

Home Posts Topics Members FAQ

default object argument

Can i do this:

function(std::string = "Hello, world"); ?

If not, is there other way that i can because my compiler (gcc 3.2) is
giving an error;

Thanks,
Anil Mamede

Jul 19 '05 #1
3 3041
On Thu, 04 Sep 2003 11:06:25 +0100, Anil Mamede wrote:
Can i do this:

function(std::string = "Hello, world"); ?

If not, is there other way that i can because my compiler (gcc 3.2) is
giving an error;


And what was the errot message then? Did you read it?

function (std::string s = "Hello, world");

hth

--
NPV
"Linux is to Lego as Windows is to Fisher Price." - Doctor J Frink

Jul 19 '05 #2
> Can i do this:

function(std::string = "Hello, world"); ?

If not, is there other way that i can because my compiler (gcc 3.2) is
giving an error;

Thanks,
Anil Mamede


It would be helpful if you said what the error was. You may even be
able to figure it out yourself if you read the error.

But, yes you can provide a default argument for function parameters of
type std::string with gcc. The following compiles with gcc
#include <iostream>
#include <string>

void f(std::string s = "test" )
{
std::cout << s << std::endl;
}

int main(int argc, char* argv[])
{
f();
f("BLA");

return 0;
}
when executed, it produces the following

test
BLA
Jul 19 '05 #3

Try this:

function(std::string("Hello, World"));

Sumit.


Sorry. Please disregard my earlier post. I had misunderstood your query.

Regards,
Sumit.
Jul 19 '05 #4

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

Similar topics

3
1766
by: Frank Bechmann | last post by:
Eventually most of you will not learn much from this because it's just another event in the 'default argument value gotcha' series, but because it cost me some hours yesterday to spot this 'error'...
18
7802
by: Dan Cernat | last post by:
Hi there, A few threads I had a little chat about default values. I am starting this thread because I want to hear more opinions about the default values of function parameters. Some say they...
5
2292
by: netvaibhav | last post by:
Hi All: Here's a piece of Python code and it's output. The output that Python shows is not as per my expectation. Hope someone can explain to me this behaviour: class MyClass: def...
44
2709
by: gregory.petrosyan | last post by:
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ????) print x All I want is to make self.data the default argument for self.f(). (I
1
11778
by: avasilev | last post by:
Hi all, I am upgrading a kind of small logging framework. Until now, the interface for logging messages takes only a format string, and a variable argument list (in a similiar way as printf())....
50
3266
by: LaundroMat | last post by:
Suppose I have this function: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to...
6
1356
by: Igor V. Rafienko | last post by:
Hi, I was wondering whether it was possible to find out which parameter value is being used: the default argument or the user-supplied one. That is: def foo(x, y="bar"): # how to figure...
4
3693
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
1
2872
by: Subrat | last post by:
Can we have a class object as default argument to a function? E.g. class A{ } A obj; class B { fun(..., A ObjA/*as default argument*/) }
2
6599
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
7227
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
7331
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,...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4713
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
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
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.