473,398 Members | 2,404 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,398 software developers and data experts.

Calling a struct constructor in a class constructor body

Hi C++ experts!

Definitely I skipped C/C++ 101 because I have this pitfall:

I need to call the struct ctor in the class default ctor body see below:

//Some.h

struct MyStruct

{

int a[5];

Nov 17 '05 #1
4 1270
Karl M wrote:
Hi C++ experts!

Definitely I skipped C/C++ 101 because I have this pitfall:

I need to call the struct ctor in the class default ctor body see
below:
Add an explicitly defined default constructor to your struct that does the
initialization:

//Some.h
#include <algorithm>
struct MyStruct

{
int a[5];
MyStruct()
{
std::fill(a,a+sizeof(a),0);
} };


HTH

-cd
Nov 17 '05 #2
> Add an explicitly defined default constructor to your struct that does the
initialization:

//Some.h
#include <algorithm>
struct MyStruct

{
int a[5];


MyStruct()
{

std::fill(a,a+5,0); }
};

--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com
Nov 17 '05 #3
Vladimir Nesterovsky wrote:
std::fill(a,a+5,0);


Yeah, that'd be better ;-) Or maybe even :

std::fill(a,a+sizeof(a)/sizeof(a[0]),0);

-cd
Nov 17 '05 #4
Thank you guys,
See my new post regarding the struct ctor

Karl M
Nov 17 '05 #5

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

Similar topics

16
by: Dave | last post by:
would someone please be so kind as to explain:
6
by: Justin | last post by:
Hello, first time posting. If I have a base class and a derived class, is there only one way to call the base constructor? i.e. Is this the only way I can call the base constructor...
4
by: Gibby Koldenhof | last post by:
Hiya, I'm setting up some code in the spirit of Design Patterns, OOP, etc. All nice and well, it handles pretty much all OO style things and serves my purposes well. There's one last final...
8
by: Pent | last post by:
Hi All, Why is this code valid? How can the static ctor be used? It doesn't act as class ctor at all. struct A { static A() { } }
31
by: Peter E. Granger | last post by:
I'm fairly new to C++ and VC++, but for the most part it seems to do most of the same things that can be done in Java, with just some syntactic and structural adjustments. However, one thing I...
3
by: Jerome Cohen | last post by:
AI am trying to call a third-party web service. this service expects an XML fragment that contains the request plus other parameter. adding the web reference created the syntax below(reference.vb)....
1
by: Fedor Semenov | last post by:
How can I call a base class' constructor from a derived class. Suppose I have: class Button // Base class { public: Button(void) { // Register classes, create the button, etc. } };
14
by: seema | last post by:
Hi all, I am new to C++ programming. Can some body explain how to intialize the structure values, consider this program, #include <iostream.h> struct mystruct { int a,b,c,d,e,f; };
10
by: Finger.Octopus | last post by:
Hello, I have been trying to call the super constructor from my derived class but its not working as expected. See the code: class HTMLMain: def __init__(self): self.text = "<HTML><BODY>";...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.