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
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
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.
"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?)
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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,...
|
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...
|
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....
|
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...
|
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...
|
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);...
|
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;}
};
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |