Hi,
look at this example:
struct T1 {
bool v;
T1(bool p = false) {
this->v = p;
}
};
struct T2 {
T1 v1;
T1 v2(true);
};
The declaration of v1 is OK.
The declaration of v2 is not. I'd like to pass the parameter to the
construtor, but i can't imagine how.
How can i pass true to the constructor?
Is it possible at all?
Regards,
Sven 4 1356
On Mon, 2007-05-14 at 03:16 +0200, Sven Köhler wrote:
struct T1 {
bool v;
T1(bool p = false) {
this->v = p;
}
};
struct T2 {
T1 v1;
T1 v2(true);
};
The declaration of v1 is OK.
The declaration of v2 is not. I'd like to pass the parameter to the
construtor, but i can't imagine how.
How can i pass true to the constructor?
Is it possible at all?
If I understand your question correctly, all you have to do is write a
constructor for T2 and initialize its 'v2' member in the initialization
list:
T2::T2() :
v2(true) {
}
I hope that helps,
--
Ney André de Mello Zunino http://zunino.eti.br/
On Mon, 14 May 2007 03:16:11 +0200, Sven Köhler wrote:
Hi,
look at this example:
struct T1 {
bool v;
T1(bool p = false) {
this->v = p;
}
};
struct T2 {
T1 v1;
T1 v2(true);
};
The declaration of v1 is OK.
The declaration of v2 is not. I'd like to pass the parameter to the
construtor, but i can't imagine how.
How can i pass true to the constructor? Is it possible at all?
Yes, you just need to do it in T2's constructor like so:
struct T2 {
T2() : v2(true) {}
T1 v1;
T1 v2;
};
--
Markus Schoder
On May 14, 9:16 am, Sven Köhler <remove-for-no-spam-skoeh...@upb.de >
wrote:
Hi,
look at this example:
struct T1 {
bool v;
T1(bool p = false) {
this->v = p;
}
};
struct T2 {
T1 v1;
T1 v2(true);
};
The declaration of v1 is OK.
The declaration of v2 is not. I'd like to pass the parameter to the
construtor, but i can't imagine how.
How can i pass true to the constructor?
Is it possible at all?
Regards,
Sven
Do that in T2's ctor:
struct T2 {
T1 v1;
T1 v2;
T2() : v2(true) {}
};
Yes, you just need to do it in T2's constructor like so:
>
struct T2 {
T2() : v2(true) {}
T1 v1;
T1 v2;
};
Exactly what i was looking for
Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: kazack |
last post by:
I am a little confused with code I am looking at. My c++ book does not go
into passing a structure to a function so I pulled out a c book which does.
and I do not understand the prototype verses the actual function call. I
will post the code below of the structure, the prototype and and function
call and if someone can explain this I would be very appreciative:
struct data
{
float amount;
string fname;
|
by: Amadeus W. M. |
last post by:
I have a member static const int x defined in class Foo, and I'm passing
it by reference, and by value elsewhere (see the code below). Passing it
by value works, but by reference it doesn't: it thinks x is undefined.
Could someone explain what's going on here? Why can't I pass a static
const member by reference?
This is how I compile it:
g++ -g -Wall sample_main.C # g++ -v 4.0.1...
|
by: Harolds |
last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005
the pmID is evaluated to "" instead of what the value is set to:
....
xmlItems.Document = pmXML
// Add the pmID parameter to the XSLT stylesheet
XsltArgumentList xsltArgList = new XsltArgumentList();
xsltArgList.AddParam("pmID", "", pmID);
xmlItems.TransformArgumentList = xsltArgList;
|
by: Ondrej Spanel |
last post by:
The code below does not compile with .NET 2003, I get folowing error:
w:\c\Pokusy\delegTemplArg\delegTemplArg.cpp(11) : error C2993: 'float' :
illegal type for non-type template parameter 'x'
The error shows compiler is quite confused - x is not a template parameter
at all.
I have found two workarounds, but still I think the code should compile.
|
by: blue |
last post by:
We often get connection pooling errors saying that there are no available
connections in the pool.
I think the problem is that we are passing around open readers all over the
place. I am planning on changing this in our code and I expect this to fix
our problem.
We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we...
| |
by: Christopher Benson-Manica |
last post by:
Does the following program exhibit undefined behavior? Specifically,
does passing a struct by value cause undefined behavior if that struct
has as a member a pointer that has been passed to free()?
#include <stdlib.h>
struct stype
{
int *foo;
};
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hi Gurus,
I need to transfer a jagged array of byte by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need to show the array data to the end user.
Can I do that?
How?
|
by: Angus |
last post by:
Hello
I am writing a library which will write data to a user defined callback
function. The function the user of my library will supply is:
int (*callbackfunction)(const char*);
In my libary do I create a function where user passes this callback
function? How would I define the function?
|
by: S. |
last post by:
Hi all,
Can someone please help me with this?
I have the following struct:
typedef struct {
char *name;
int age;
} Student;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |