473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

default struct argument, how?

Hi there.

I want to use a default argument declared as a struct, something like:

struct mystruct { int a; int b; };
void myfunc ( mystruct x = {0, 1} )
{
// Do something
}

But my compiler (Visual Studio 2005) just complains. So, what is wrong with
the above?

Thanks in advance
Pär
Dec 19 '06 #1
3 5789

Pär Buschka wrote:
Hi there.

I want to use a default argument declared as a struct, something like:
structure with default values or ......
struct mystruct { int a; int b; };
void myfunc ( mystruct x = {0, 1} )
{
// Do something
}

But my compiler (Visual Studio 2005) just complains. So, what is wrong with
the above?

Thanks in advance
Pär
Could you tell the purpose of myfunc() function???

Dec 19 '06 #2
Pär Buschka wrote:
Hi there.

I want to use a default argument declared as a struct, something like:

struct mystruct { int a; int b; };
void myfunc ( mystruct x = {0, 1} )
{
// Do something
}

But my compiler (Visual Studio 2005) just complains. So, what is wrong
with the above?
Well, it's invalid syntax. What you can do is give it a constructor:

struct mystruct
{
mystruct(int a, int b) : a(a), b(b) {}
int a; int b;
};

void myfunc ( mystruct x = mystruct(0, 1) )
{
// Do something
}
Dec 19 '06 #3
"Pär Buschka" <pe**@home.sewrote in message
news:CV*******************@newsb.telia.net
Hi there.

I want to use a default argument declared as a struct, something like:

struct mystruct { int a; int b; };
void myfunc ( mystruct x = {0, 1} )
{
// Do something
}

But my compiler (Visual Studio 2005) just complains. So, what is
wrong with the above?

Thanks in advance
Pär
An alternative to Rolf's suggestion is:

struct mystruct { int a; int b; };
mystruct initializer = {0,1};
void myfunc ( mystruct x = initializer)
{
// Do something
}
--
John Carson
Dec 19 '06 #4

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

Similar topics

6
by: Patrick Kowalzick | last post by:
Dear all, I have a question about default template parameters. I want to have a second template parameter which as a default parameter, but depends on the first one (see below). Is something...
3
by: Capstar | last post by:
Hi NG, I am trying to get the attached piece of code to work, but I can't figure out what I'm doing wrong. To me it seems that when I don't pass an argument to x::do_something, it should use the...
5
by: asianmuscle | last post by:
I am trying to learn RAII and some template techniques by writer a smarter pointer class to manage the resource management. Since I find that a lot of the resource management is kinda the same, I...
3
by: IR | last post by:
Hi, I've been trying to do the following (which doesn't compile) : template<class T, class F = Example<T struct Example { F foo(); };
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.