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

class object initialisation

A
Hi,

I have always been taught to use an inialization list for initialising data
members of a class. I realize that initialsizing primitives and pointers use
an inialization list is exactly the same as an assignment, but for class
types it has a different effect - it calls the copy constructor.

My question is when to not use an initalisation list for initialising data
members of a class?
Regards
Adi

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.516 / Virus Database: 313 - Release Date: 1/09/2003
Jul 19 '05
106 5454
Alexander Terekhov wrote:
Attila Feher wrote:

Alexander Terekhov wrote:
White Wolf wrote:
I can copy it around. (at lest I hope so).

Nope. You can't copy it AS POINTER. std::vector<unsigned char> will
work, though. ;-)


Not even as void?


void pointer? It will also not work. You'll hit undefined
behavior as soon as you try to 'use' deleted/freed pointer
as pointer...


But that was the *whole* point: I do *not* want to use it as a pointer. I
never want to dereference it or apply arithmetics to it.

--
Attila aka WW
Jul 19 '05 #101
tom_usenet wrote:
Nope. You can't copy it AS POINTER. std::vector<unsigned char> will
work, though. ;-)


Not even as void?


This is illegal, even though it isn't dereferenced:

void* p = ::operator new(1);
operator delete(p);

void* q = p; // boom

You aren't allowed to convert a pointer to an rvalue after deleting
it. You can of course reassign it:
p = 0; //or whatever.


Ahha. Makes sense, but quite restrictive. So basically you will need to
store it as "whatever", but not as a pointer if you want to keep the value
around.

--
Attila aka WW
Jul 19 '05 #102

Attila Feher wrote:
[...]
Ahha. Makes sense, but quite restrictive. So basically you will need to
store it as "whatever", but not as a pointer if you want to keep the value
around.


Even if you store it BEFORE free-ing... since the representation
may have quite a few garbage bits, storing it as "whatever" will
be nothing but "absolutely pointless exercise"... well, just a
few exceptions (I have a patent appl on one of those ;-) ) aside,
of course.

regards,
alexander.
Jul 19 '05 #103

"Gary Labowitz" <gl*******@comcast.net> wrote in message
news:sj********************@comcast.com...
"jeffc" <no****@nowhere.com> wrote in message
news:3f********@news1.prserv.net...

Check what you wrote 2 posts ago. You're going around in circles.


It's called a loop.


Just trying to give the guy a break.
(get it?)
Jul 19 '05 #104
Alexander Terekhov wrote:
Attila Feher wrote:
[...]
Ahha. Makes sense, but quite restrictive. So basically you will
need to store it as "whatever", but not as a pointer if you want to
keep the value around.


Even if you store it BEFORE free-ing... since the representation
may have quite a few garbage bits, storing it as "whatever" will
be nothing but "absolutely pointless exercise"... well, just a
few exceptions (I have a patent appl on one of those ;-) ) aside,
of course.


Since looking at them later is a "platform dependent exercise" I believe
that whatever garbage bits they have it does not really matter at all.

class DeadPtr {
unsigned char bitz[sizeof(void*)]; // Could be char *
public:
DeadPtr( void const* p) { memcpy and so on}
DeadPtr( void const* const p) { memcpy and so on}
// Something special/platform dependent to display it
};

Off course ;-) this thingy has to be made _before_ the delete is being
called. I dunno if passing as reference counts as use as rvalue... if not
that can be done.

--
Attila aka WW
Jul 19 '05 #105
Gary Labowitz wrote:
[SNIP]
Well, I like your obfuscation! I didn't understand anything! It's
ready for publication!
On the serious side, the fact that there are invalid combinations of
bits for types introduces a whole new complexity for me, and makes
the standard almost unbearably complex. Oh well, reality must be
faced.
On the whole, I rather prefer Java: nine simple types to learn about,
all well defined with regard to bit usage and size, no surprises.


Nine types? No surprises? I dunno, but whenever I had to try to find
something in the Java libraries (find+understand) I finally gave up. It is
like having to talk to all Chineese and Indian people to find a street
address. Messy.

Anyways. C++ is a general purpose programming language with systems
programming in mind. Comparing it to Java is like comparing apples to the
moon.

--
WW aka Attila
Jul 19 '05 #106
Gary Labowitz wrote:
Thank you. If this be the case, then all my musings are incorrect.
Hmm... check sum bits in a value. Yes, it could. Then invalid bit
combinations could exist. All resulting in undefined behavior I
should think.
Yep. In fact of life it is quite unusual for the "common people" to find a
HW which works like this. Anyways using a garbage value is not a really
good thing to do, even if one can get away with it without a crash.
Back to the drawing board!!!
[Gee, what did we go back to before they invented drawing boards?]


Me go bangbang wife. :-) Or maybe: back to the cave wall. :-)

--
WW aka Attila
Jul 19 '05 #107

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

Similar topics

1
by: matro | last post by:
hi there, I have the following struct in my class: class CTbStDialog : public CDialog { public: int fooVar, fooVar2; ... //other foo variables...
8
by: jose luis fernandez diaz | last post by:
Hi, I am reading Stroustrup's book 'C++ Programming Language'. In the 10.4.9 section (Nonlocal Store) he says: "A variable defined outside any function (that is global, namespace, and class...
11
by: Neil Zanella | last post by:
Hello, When an "std::map<int, int> foobar;" statement appears in a C++ program followed by a statement of the form "foobar;" where nothing has ever been inserted at position 123 into map foobar,...
3
by: deancoo | last post by:
I'm hoping this isn't too off topic, but I'm not sure if I've included some of my member functions in the right class. I needed to develop numerous functions to help define object A. These...
13
by: Frederick Gotham | last post by:
I have just been reading 8.5 in the Standard, and am trying to make sense of the different kinds of initialisations. Up until now, I thought of an object as either NOT being initialised (i.e....
16
by: silversurfer2025 | last post by:
Hello everyone, once again, I have a very basic problem in C++, which I was not able to solve (maybe because of my Java-Experience or just because it is always the small syntax-things which break...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
2
by: .rhavin grobert | last post by:
i have (do try to have?) the following... & = breakpoints in debugger // ---------------------------------------------------------------- // cx.h class CX { public: CX(CX* pcx = NULL);...
13
by: Anarki | last post by:
#include <iostream> using namespace std; class ConstantMember { const int m_const; public: ConstantMember(int cons = 10):m_const(cons){} int getConst() const{ return m_const;} };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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.