http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* size_t Question - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/d04eb033c399a55c?hl=en
* C++ function argument with 'class' keyword? - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/f43dbb9087b23386?hl=en
* Why does a vector fail here? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/0f7f65bf6f4a8aa4?hl=en
* EXC_BAD_ACCESS during Copy Constructor - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/4df988891eedf2bd?hl=en
* Real overload or not ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/b8c3930fe90b382b?hl=en
* Support for export keyword ? - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0878ed0c9c1ca584?hl=en
* How to get the distance (hops) between NUMA nodes? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/b61459ea866da088?hl=en
* Nested template specialization - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/da1990456413a63a?hl=en
* Make Money Rs. 1000 per day My Dear Friends, I tried a lot of works in
online business, finally I find one guniune opportunity. That's www.time2rich.
com/r9a9m9 At www.time2rich.com/r9a9m9 you will have international business,
with just star - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/58879de2a25f8654?hl=en
* I'm a newbie. Is this code ugly? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/f085e44989fab5ef?hl=en
* ۞۩๑۞۩ HOT Sale AAA True Leather brand handbags: Chanel handbag, Gucci
handbag, LV handbag ect at www.fjrjtrade.com <paypal payment> - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/cdc0cab82fb5e01a?hl=en
* ☆°ω°☆【Paypal】 Wholesale Cheap Boots brand shoes ( www.ecyaya.com ) - 1
messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/5a36642586151678?hl=en
==============================================================================
TOPIC: size_t Question
http://groups.google.com/group/comp.lang.c++/t/d04eb033c399a55c?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Jan 24 2010 1:14 pm
From: Öö Tiib
On Jan 24, 8:45 pm, "Leigh Johnston" <le...@i42.co.uk> wrote:
> " Tiib" <oot...@hot.ee> wrote in message
>
> news:d20fadd7-fdd9-48bd-a39e-be9b41997f28@b10g2000yqa.googlegroups.com...
>
>
>
>
>
> > On Jan 24, 5:05 pm, "Leigh Johnston" <le...@i42.co.uk> wrote:
> >> > For array of char size_t must therefore be same size as ptrdiff_t.
>
> >> Unless we are talking about crappy corner case implementations that Mr
> >> Kanze
> >> likes so much. What is the point of having a 64bit address space if you
> >> can
> >> only allocate 32bits worth of objects/arrays?
>
> > Because it may be is optimal/required by platform architecture that
> > does not let one to have continuous memory block over 4 Gigabytes. C
> > is meant to be as close to assembler as any platform independent
> > language can get and size_t is C not C++ typedef. You may think it
> > makes it difficult to program, but it may prove to be best and
> > quickest and so users will buy it. At second thought it may even sound
> > reasonable. How often you deal with single object that does not fit
> > into 4 gigabytes?
>
> A single object might need to fit into 4 gigabytes however an array of such
> objects might not. The difference between a single object or an array of
> objects should not important as far as pointer arithmetic is concerned.
Yes that was what i was asking. Array is single object like any other.
How often you needed 4GB array? With array it is simpler matter to
solve on such platform since you can have array of pointers to its
elements.
== 2 of 2 ==
Date: Sun, Jan 24 2010 5:25 pm
From: James Kanze
On Jan 24, 2:49 pm, "Leigh Johnston" <le...@i42.co.uk> wrote:
> "James Kanze" <james.ka...@gmail.com> wrote in message
> news:7dee3511-bace-4973-b915-8fd7666a139a@a22g2000yqc.googlegroups.com...
> > On Jan 23, 7:10 am, "io_x" <a...@b.c.invalid> wrote:
> >> "Immortal Nephi" <Immortal_Ne...@hotmail.com> ha scritto nel
> >> messaggionews:8d88539d-ac35-45a4-bdd3-9ebdc5023165@p24g2000yqm.googlegroups.com...
> > [...]
> >> size_t has one range that allow all possible address
> > No. All that is required is that it can hold the size of
> > the largest possible object. I've used systems with 32 bit
> > addresses but 16 bit size_t. (I suspect that most people my
> > age has, since this was the case on the most widespread
> > machines twenty-five or thirty years ago.)
> size_t is also used for array indexing so on a 64bit system
> for example it should be the same size as ptrdiff_t.
The standard requires ptrdiff_t and size_t to have the same
size. (Logically, one would expect size_t to be smaller, since
it doesn't need the sign bit.) But that doesn't change
anything: all that is required is that size_t be large enough to
contain the size of the largest possible object. Since arrays
are objects, that means that it can index into any possible
array.
The larger the word size of the machine, the less likely that it
will be smaller than a pointer. But a lot of 16 bit
architectures, and at least one 32 bit architecture (Intel)
support pointers larger than the word size: I've worked on
systems where the largest possible single object was 2^16 bytes,
but that could address 1 MB, and on machines where the largest
possible single object was 2^32, but pointers are 48 bits.
--
James Kanze
==============================================================================
TOPIC: C++ function argument with 'class' keyword?
http://groups.google.com/group/comp.lang.c++/t/f43dbb9087b23386?hl=en
==============================================================================
== 1 of 4 ==
Date: Sun, Jan 24 2010 1:34 pm
From: "Johannes Schaub (litb)"
James Kanze wrote:
> On Jan 23, 2:34 pm, Pete Becker <p...@versatilecoding.com> wrote:
>> xhm wrote:
>
>> > 1) bool test(class A &mya);
>
>> > where A is a class name and mya is an object name.
>
>> > I am wondering the meaning of the 'class' keyword in this
>> > declaration. I would think it can be declared as:
>
>> It means that A is the name of a class (or struct or union,
>> but don't worry about that wrinkle for now).
>
> Are you sure about union? I don't have my copy of the standard
> (or any draft, for that matter) handy to check, but I seem to
> remember that unions got special handling in this regard. (A
> union is a class... except when it isn't.)
>
I think you have the IsClass and IsClassType concepts of c++0x in mind,
which made a difference between union and struct/class. But in general,
unions indeed are classes (so for instance, it's indeed possible to have
"union templates" without anything explicitly stating that in the Standard).
What is not allowed is "enum A &mya".
>> > 2) bool test(A &mya)
>
>> > what's the difference between 1) and 2). Or the 'class'
>> > keyword in 1) actually is not necessary? I tried to search
>> > on the Internet but didn't find an answer.
>
>> The difference is that without more, the first is valid and
>> the second isn't. In order for the second one to compile there
>> has to be a previous declaration of A.
>
>> bool test(A &mya); // error: A not defined
>> bool test(class A &mya); // OK: A names a class
>
> IIRC, it's more subtle than that. The second names a class in
> function prototype scope. And I don't see where you're going to
> be able to define a class in function prototype scope, so the
> second effectively names a class which can't be defined.
>
That's only the case in C. In C++ such a class will be a member of the
enclosing namespace, as said by 3.3.2/6. Granted, it just says that the
class-name is declared in the enclosing namespace. But its intent seems that
the class is also a member of that namespace (so, scope of a name determines
identity of the entity referred to, here).
In C you will only be able to define such a type by having a struct
declaration for the new type placed into another TU, because the first
declaration and the second declaration of the tag identifier will refer to
different entities if you try to define the type in the same TU. If you
define it in another TU and then in that other TU define the function, then
both functions across the TU are of compatible types (not the same - but
that's not necessary) and behavior is well defined. Scopes are not used for
randomly determining identity of an entitiy in C (but merely linkage does -
and identifiers of types have no linkage).
This code works on comeau and GCC (getting back to C++ again), and indeed
shows that the class is a member of the enclosing namespace, rather than a
local class or something else:
void f(class X);
class X { };
void f(X x) { }
int main() {
&f; // f is not an overloaded function
}
> (From memory. And this is really the sort of question where I
> miss not having my copy of the standard handy, because name
> lookup isn't always that trivial.)
>
Yeah, name lookup and especially rules about declarative regions and scopes
and identity are confusing in my opinion :(
>> ------------------
>
>> class A;
>> bool test(A &mya); // OK
>> bool test(class A &mya); // OK
>
>> ------------------
>
>> class A
>> {
>> // whatever...};
>
>> bool test(A& mya); // OK
>> bool test(class A& mya); // OK
>
>> ------------------
>
>> bool test(class A& mya); // OK
>
>> On the other hand, the declaration within a function prototype
>> only applies within the prototype:
>
>> bool test(class A& mya); // OK
>> bool also_test(A& may); // error: A not defined
>
>> This kind of on-the-fly declaration isn't used much any more.
>
> Except in header files which have to be used in both C and C++
> (in which case, of course, it's "struct A*", and not "class
> A&").
>
Tho i believe most people will go the easy way and do "struct A;" at the
start of those function declarations, rather than sprinkling the code with
those in-line forward declarations :)
== 2 of 4 ==
Date: Sun, Jan 24 2010 2:00 pm
From: "Johannes Schaub (litb)"
Johannes Schaub (litb) wrote:
> James Kanze wrote:
>
>> On Jan 23, 2:34 pm, Pete Becker <p...@versatilecoding.com> wrote:
>>> xhm wrote:
>>> > 2) bool test(A &mya)
>>
>>> > what's the difference between 1) and 2). Or the 'class'
>>> > keyword in 1) actually is not necessary? I tried to search
>>> > on the Internet but didn't find an answer.
>>
>>> The difference is that without more, the first is valid and
>>> the second isn't. In order for the second one to compile there
>>> has to be a previous declaration of A.
>>
>>> bool test(A &mya); // error: A not defined
>>> bool test(class A &mya); // OK: A names a class
>>
>> IIRC, it's more subtle than that. The second names a class in
>> function prototype scope. And I don't see where you're going to
>> be able to define a class in function prototype scope, so the
>> second effectively names a class which can't be defined.
>>
> That's only the case in C. In C++ such a class will be a member of the
> enclosing namespace, as said by 3.3.2/6. Granted, it just says that the
> class-name is declared in the enclosing namespace. But its intent seems
> that the class is also a member of that namespace (so, scope of a name
> determines identity of the entity referred to, here).
>
> In C you will only be able to define such a type by having a struct
> declaration for the new type placed into another TU, because the first
> declaration and the second declaration of the tag identifier will refer to
> different entities if you try to define the type in the same TU. If you
> define it in another TU and then in that other TU define the function,
> then both functions across the TU are of compatible types (not the same -
> but that's not necessary) and behavior is well defined. Scopes are not
> used for randomly determining identity of an entitiy in C (but merely
> linkage does - and identifiers of types have no linkage).
>
I'm wrong on the last sentence. You can do the following in C:
struct X;
struct X { int a; };
And both declarations declare tags for the same type. This is not because of
linkage, though, but because of additional constraints that struct specifier
in the same scope with the same tag declare the same type. In the following
the specifiers appear in different scopes, so they specify different types,
and they are not compatible since they are not declared in different TUs:
void f(struct X x);
void f(struct X { int a; } x) { }
That's why we need to place the definition in another TU, so that type
compatibility rules then make both types compatible and make it well
defined.
Alright, i just wanted to see how this behaves in C. I'm sorry for the
offtopicness :)
== 3 of 4 ==
Date: Sun, Jan 24 2010 5:27 pm
From: James Kanze
On Jan 24, 4:29 pm, Pete Becker <p...@versatilecoding.com> wrote:
> James Kanze wrote:
> > On Jan 23, 2:34 pm, Pete Becker <p...@versatilecoding.com> wrote:
> >> The difference is that without more, the first is valid and
> >> the second isn't. In order for the second one to compile there
> >> has to be a previous declaration of A.
> >> bool test(A &mya); // error: A not defined
> >> bool test(class A &mya); // OK: A names a class
> > IIRC, it's more subtle than that. The second names a class in
> > function prototype scope.
> Sigh. See below:
Sorry, I wrote that before seeing below...
> >> On the other hand, the declaration within a function prototype
> >> only applies within the prototype:
> >> bool test(class A& mya); // OK
> >> bool also_test(A& may); // error: A not defined
And after seeing this, I meant to drop the article. I must have
hit the wrong button.
--
James Kanze
== 4 of 4 ==
Date: Sun, Jan 24 2010 6:01 pm
From: James Kanze
On Jan 24, 9:34 pm, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
> James Kanze wrote:
> > On Jan 23, 2:34 pm, Pete Becker <p...@versatilecoding.com> wrote:
> >> xhm wrote:
> >> > 1) bool test(class A &mya);
> >> > where A is a class name and mya is an object name.
> >> > I am wondering the meaning of the 'class' keyword in this
> >> > declaration. I would think it can be declared as:
> >> It means that A is the name of a class (or struct or union,
> >> but don't worry about that wrinkle for now).
> > Are you sure about union? I don't have my copy of the
> > standard (or any draft, for that matter) handy to check, but
> > I seem to remember that unions got special handling in this
> > regard. (A union is a class... except when it isn't.)
> I think you have the IsClass and IsClassType concepts of c++0x in mind,
Certainly not, since I'm not familiar with them.
> which made a difference between union and struct/class. But in
> general, unions indeed are classes (so for instance, it's
> indeed possible to have "union templates" without anything
> explicitly stating that in the Standard).
As I said, unions are classes, except when they aren't. A union
cannot have a base class, for example, nor can it have virtual
functions. I have a vague memory that there was also a
(specific) requirement that unions must be declared with union,
and non-union classes with struct or class, but I can't find it
in the 1998 version of the standard on my backup, and I can't
access the 2003 version. (The backup is from a Linux system,
and the name of the 2003 version is 14882:2003.pdf. I'm
currently under Windows, and it doesn't seem to like this
name:-).)
Anyway, it's a memory. I'm not sure it's correct. (But I seem
to recall thinking like you, and having someone point the
restriction out to me.)
> What is not allowed is "enum A &mya".
Nor things with typedef.
> >> > 2) bool test(A &mya)
> >> > what's the difference between 1) and 2). Or the 'class'
> >> > keyword in 1) actually is not necessary? I tried to search
> >> > on the Internet but didn't find an answer.
> >> The difference is that without more, the first is valid and
> >> the second isn't. In order for the second one to compile
> >> there has to be a previous declaration of A.
> >> bool test(A &mya); // error: A not defined
> >> bool test(class A &mya); // OK: A names a class
> > IIRC, it's more subtle than that. The second names a class
> > in function prototype scope. And I don't see where you're
> > going to be able to define a class in function prototype
> > scope, so the second effectively names a class which can't
> > be defined.
> That's only the case in C. In C++ such a class will be a
> member of the enclosing namespace, as said by 3.3.2/6.
> Granted, it just says that the class-name is declared in the
> enclosing namespace. But its intent seems that the class is
> also a member of that namespace (so, scope of a name
> determines identity of the entity referred to, here).
In the 1998 version of the standard, there is no 3.3.2/6, but
§3.3.3 is quite clear that there is a "function prototype
scope", and §3.4.3 makes it clear that if there is no previous
delcaration of the class, the qualified name is treated as a
declaration. In scope.
The only case I'm aware of where a name is declared in a scope
other than that of the declaration is in friend declarations.
--
James Kanze
==============================================================================
TOPIC: Why does a vector fail here?
http://groups.google.com/group/comp.lang.c++/t/0f7f65bf6f4a8aa4?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Jan 24 2010 1:39 pm
From: JoeC
I am writing a program to display bitmaps and I want to use a vector
to hold my bitmap data but when I use this algorithm it fails:
for(index = 0; index < dwn; index++){
memcpy(&temp[((dwn-1) - index)*acc],
&bitData[index*acc],acc);}
The vector is declared in the header and in the constuctor I fill it
with zeros as a default.
Size is = acc*dwn;
Default 16*16 bitmap;
for(int lp = 0; lp != size; lp++){
bitData.push_back(0);
}
If I add this the program does not crash:
BYTE* bitmap::flip(){
int acc = bmi.bmiHeader.biWidth;
int dwn = bmi.bmiHeader.biHeight;
int index;
BYTE *temp2 = new BYTE[bitData.size()];
for(int l=0; l < bitData.size();l++){
temp2[l]=bitData[l];
}
BYTE * temp = new BYTE[acc*dwn];
for(index = 0; index < dwn; index++){
memcpy(&temp[((dwn-1) - index)*acc],
&temp2[index*acc],acc);}
return temp;
}
I have written a bitmap before and used a vector to hold the graphics
data but this object trying to do a DIB bitmap is giving me all kinds
of problems. The algorithm works in a function but when I try to put
the same information in an object it fails. Anything else I can add
to help explain the problem. I often have problems asking questions
on more complex problems because it can be cumbersome to post from
several files both .h and .cpp.
== 2 of 2 ==
Date: Sun, Jan 24 2010 2:12 pm
From: Öö Tiib
On Jan 24, 11:39 pm, JoeC <enki...@yahoo.com> wrote:
> I am writing a program to display bitmaps and I want to use a vector
> to hold my bitmap data but when I use this algorithm it fails:
>
> for(index = 0; index < dwn; index++){
> memcpy(&temp[((dwn-1) - index)*acc],
> &bitData[index*acc],acc);}
Seems algorithm like any other how it fails? This sounds like simple
typo outside of what you have posted.
>
> The vector is declared in the header and in the constuctor I fill it
> with zeros as a default.
The vector named 'temp'? Usually people do not declare such vectors in
header files.
> Size is = acc*dwn;
> Default 16*16 bitmap;
This can not compile. You have to describe a context where it
compiles.
> for(int lp = 0; lp != size; lp++){
> bitData.push_back(0);
> }
Usually this is done in constructor like:
std::vector<BYTE> bitData(size, 0);
> If I add this the program does not crash:
>
> BYTE* bitmap::flip(){
>
> int acc = bmi.bmiHeader.biWidth;
> int dwn = bmi.bmiHeader.biHeight;
> int index;
>
> BYTE *temp2 = new BYTE[bitData.size()];
> for(int l=0; l < bitData.size();l++){
> temp2[l]=bitData[l];
> }
>
> BYTE * temp = new BYTE[acc*dwn];
>
> for(index = 0; index < dwn; index++){
> memcpy(&temp[((dwn-1) - index)*acc],
> &temp2[index*acc],acc);}
>
> return temp;
> }
Yes. If this does not crash then all is fine with bitData vector.
Problem is with these temps of yours ... or odd variables with 3
character names.
> I have written a bitmap before and used a vector to hold the graphics
> data but this object trying to do a DIB bitmap is giving me all kinds
> of problems. The algorithm works in a function but when I try to put
> the same information in an object it fails. Anything else I can add
> to help explain the problem. I often have problems asking questions
> on more complex problems because it can be cumbersome to post from
> several files both .h and .cpp.
Do not worry. Free land and non-moderated group. Make example (as
lengthy as you made non-crashing one) with vector usage that crashes.
It is highly probable you discover your mistake in the process.
==============================================================================
TOPIC: EXC_BAD_ACCESS during Copy Constructor
http://groups.google.com/group/comp.lang.c++/t/4df988891eedf2bd?hl=en
==============================================================================
== 1 of 3 ==
Date: Sun, Jan 24 2010 3:04 pm
From: Philip Lee Bridson
Good Evening,
I have been writing apps in C++ for a while now but I have to admit
the below problem has stumped me - I would not consider myself an
'expert' but also I am not a novice. Any help would be appreciated.
I have a copy constructor which is defined as follows:
Object::Object(const Object& o) {
if (o != NULL) {
if (_internalObject != NULL) {
delete _internalObject;
_internalObject = NULL;
}
_message = ex.Message();
if (o.InternalObject() != NULL) {
_internalObject = new Object();
_internalObject = ex.InternalObject();
}
}
}
When I get to the line that deletes the internal object (which is a
pointer that is initialized during the constructor) I get
EXC_BAD_ACCESS. I have debugged the app and I can confirm that I am
not calling a double free() and that _internalObject actually does
piont to something.
The code from which the copy constructor is initiated is below...
Object * o = new Object();
if (o != NULL) {Object p = *o; //etc....}
the app only crashes when I copy the object, all other constructors
are fine. Does anyone have any ideas what may cause this?
Many thanks in advance.
Phil.
== 2 of 3 ==
Date: Sun, Jan 24 2010 3:43 pm
From: Öö Tiib
On Jan 25, 1:04 am, Philip Lee Bridson <philip.brid...@googlemail.com>
wrote:
> Good Evening,
>
> I have been writing apps in C++ for a while now but I have to admit
> the below problem has stumped me - I would not consider myself an
> 'expert' but also I am not a novice. Any help would be appreciated.
>
> I have a copy constructor which is defined as follows:
>
> Object::Object(const Object& o)
Where is
: _intrnalObject( NULL )
???
Add it to initialize _internalObject.
> {
>
> if (o != NULL) {
how can you compare o with NULL? Does it have operator int or
operator != (int)?
> if (_internalObject != NULL) {
> delete _internalObject;
> _internalObject = NULL;
> }
Your _internalObject is not initialized, so it possibly points at
garbage. Initialize it and remove above block.
>
> _message = ex.Message();
What is ex?
>
> if (o.InternalObject() != NULL) {
> _internalObject = new Object();
> _internalObject = ex.InternalObject();
> }
> }
> }
>
> When I get to the line that deletes the internal object (which is a
> pointer that is initialized during the constructor) I get
> EXC_BAD_ACCESS. I have debugged the app and I can confirm that I am
> not calling a double free() and that _internalObject actually does
> piont to something.
>
> The code from which the copy constructor is initiated is below...
>
> Object * o = new Object();
>
> if (o != NULL) {Object p = *o; //etc....}
>
> the app only crashes when I copy the object, all other constructors
> are fine. Does anyone have any ideas what may cause this?
>
> Many thanks in advance.
>
> Phil.
== 3 of 3 ==
Date: Sun, Jan 24 2010 3:45 pm
From: Victor Bazarov
Philip Lee Bridson wrote:
> Good Evening,
>
> I have been writing apps in C++ for a while now but I have to admit
> the below problem has stumped me - I would not consider myself an
> 'expert' but also I am not a novice. Any help would be appreciated.
>
> I have a copy constructor which is defined as follows:
>
> Object::Object(const Object& o) {
So, this is a constructor, right? Any member have been initialized yet?
Probably not (you don't have any initializer list, do you?), so what
do you expect their values are? You compare '_internalObject', which
has some indeterminate value here, to NULL. Why would it be NULL except
by chance? Oh, it can be NULL if your 'Object' is static, yes. But you
don't usually copy-construct statics, do you?
>
> if (o != NULL) {
Your 'Object' has a conversion to 'int'? Why would you compare 'o' to 0
here?
> if (_internalObject != NULL) {
> delete _internalObject;
> _internalObject = NULL;
> }
It seems you copied your *constructor* code from an assignment operator
or something like that. Well, don't. And if you do copy code from some
other place, you *should* examine it carefully to ensure that every line
of your code makes sense in the *new location of the code*.
>
> _message = ex.Message();
>
> if (o.InternalObject() != NULL) {
> _internalObject = new Object();
> _internalObject = ex.InternalObject();
> }
> }
> }
>
> When I get to the line that deletes the internal object (which is a
> pointer that is initialized during the constructor)
It's NOT a pointer that is initialized to anything at the time you're
trying to delete it.
> I get
> EXC_BAD_ACCESS. I have debugged the app and I can confirm that I am
> not calling a double free() and that _internalObject actually does
> piont to something.
What does it point to? Anything you have control over?
> The code from which the copy constructor is initiated is below...
>
> Object * o = new Object();
>
> if (o != NULL) {Object p = *o; //etc....}
'o' is never NULL when 'new' returns it. 'new' throws if you don't have
enough memory (or if the constructor throws).
> the app only crashes when I copy the object, all other constructors
> are fine. Does anyone have any ideas what may cause this?
Yes, just like I told you above, since '_internalObject' is not
initialized to anything, it contains some random garbage that you make
the machine interpret as a pointer to something. The machine cannot
make sense of it, and you get notified.
This is what your code should look like:
Object::Object(const Object &other)
: _internalObject(other._internalObject ?
new Object(*other._internalObject) : 0)
{
}
And just for completeness' sake, read about "the Rule of Three" if you
haven't yet.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
==============================================================================
TOPIC: Real overload or not ?
http://groups.google.com/group/comp.lang.c++/t/b8c3930fe90b382b?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 24 2010 5:04 pm
From: James Kanze
On Jan 22, 9:20 am, Christophe Bourez <bou...@gmail.com> wrote:
> I am reviewing the coding guideline of an organisation and one
> of them states that the name of the function members should
> start with an 'r' if the function returns a non-const
> reference (I don't want to debate whether returning a
> non-const ref is a good practice or not). Here follows an
> example
> class A
> {
> public:
> int &rGetValue();
> const int &GetValue() const;
> ...
> };
That smacks of Hungarian. In the bad sense. On the other hand,
it is quite normal for a function which allows or supports
modification of internal state to have a different names, or at
least a different signature, from one which doesn't. After all,
they're doing different things. Thus, one would expect:
int GetValue() const;
void PutValue(int newValue);
or
int value() const;
void value(int newValue);
(To give the two most frequent conventions.)
About the only case I can think of where a const and a non-const
function should be overloaded is for operator overloading.
> Clearly, without the 'r', const and non const versions of GetValue
> should have been considered as an overload.
Which is something you definitely want to avoid. It's the means
which are bad, not the end.
> Prefixing the 'r' makes obviously these member functions not
> real overload. Personally, I really hate this kind of rule,
> but it is just a matter of taste. Could you give me good
> reasons to prefer a real overload?
Obfuscation? The possibility to create obscure bugs?
> For example, could this kind of rule prevent the reuse of
> generic code, by the fact that their names are not aligned?
No.
--
James Kanze
==============================================================================
TOPIC: Support for export keyword ?
http://groups.google.com/group/comp.lang.c++/t/0878ed0c9c1ca584?hl=en
==============================================================================
== 1 of 2 ==
Date: Sun, Jan 24 2010 5:11 pm
From: James Kanze
On Jan 24, 5:37 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> James Kanze wrote:
> >> Could you give some examples of the difficulties which pop up
> >> with that?
> > Could you explain to me why you think it is so simple.
> Because you can emulate export templates to a degree with
> manual instantiation.
No you can't. Almost by definition. If you're doing it, it's
not the compiler which is doing it. And the whole point of C++
templates is that the compiler does it. I've played that game
of manual instantiation with <generic.h>, before we had
templates, and I can assure you that it isn't viable for
anything but the simplest uses of templates. And of course, the
semantics of an exported template are different than those of a
non-exported template.
> In other words, in the header file you can simply have the
> declaration of the template class or template function (ie.
> not its definition), and then in a source file you can
> implement the definition and then in that file instantiate it
> manually for each type with which the template is being used
> in the program.
> I have done that in practice and it works.
In the very limited cases you've tried, perhaps. A compiler has
to work for every legal case.
> >> One would think that it wouldn't be so much different as when
> >> the programmer does the same thing "manually".
> > The programmer never does the same thing manually. To do so
> > would be too difficult.
> It's quite simple to do, at least for simple template types.
For simple uses of simple types, yes. The standard requires
export to work for all legal uses. That's a big difference.
> > Except that the results won't compile.
[...]
> The above example compiles at least with gcc and Visual C++.
But it doesn't solve the problem. You've shown that in one
simple case it can be made to work. That's not what's required.
It has to work in all legal cases.
--
James Kanze
== 2 of 2 ==
Date: Sun, Jan 24 2010 5:18 pm
From: James Kanze
On Jan 24, 5:25 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> io_x wrote:
> > and the compiler has to use the funtions in this way
> > Image<double> g(768, 1024);
> > call the constructor:
> > Image(sizeof(double), 768, 1024)
> > so all the routines that use the generic type (that has to
> > use sizeof(T)) can be ok like above if pass sizeof(T)
> I don't think you understand how export templates work. Export
> templates are no different from regular templates.
Yes they are. They eliminate a lot of undefined behavior, for
example.
> They are not (and cannot be) compiled to object files prior to
> their actual instantiation. They are compiled *after* they
> have been instantiated, just like regular templates.
Not quite like regular templates. When a regular template is
instantiated, the instantiation occurs at a specific place in
the source code, with all of the preceding context present.
It's possible to implement export this way as well, but it sort
of defeats the purpose, and it still requires additional work,
because the instantiation must be compiled as if parts of the
preceding context are not present.
> Yes, the linker stage has to call the C++ compiler in order to
> instantiate export templates with the proper types, after
> which they are compiled more or less like regular templates.
That's not necessarily true. First, if it calls the C++
compiler, it must be able to synthesize the correct context for
the instantiation (which is far from trivial). And better
compilers will still have the intermediate representation
present at link time (since it is necessary for advanced
optimization), and all the instantiation needs is some form of
the intermediate representation.
--
James Kanze
==============================================================================
TOPIC: How to get the distance (hops) between NUMA nodes?
http://groups.google.com/group/comp.lang.c++/t/b61459ea866da088?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 24 2010 5:37 pm
From: red floyd
On 1/24/2010 12:29 AM, ttt wrote:
>
> Thanks. libnuma has a 'distance' function which does what I want. But
> I'm more interested in support for Windows.
> I've found a new function that appeared in Win7 GetNumaProximityNode
> but I couldn't understand from the documentation how it's supposed to
> work. Has anyone used this function ?
At this point, you are better off asking in a Windows forum. You might
seriously consider MSDN.
==============================================================================
TOPIC: Nested template specialization
http://groups.google.com/group/comp.lang.c++/t/da1990456413a63a?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 24 2010 6:52 pm
From: Sam
I've been trying to figure out how to take a class template that takes one
template class parameter, that defines an inner member template class, that
also one class parameter; then specialization the inner member template
class whose template class parameter is the same as the outer template
class's class parameter.
After failing to figure out how to do it directly, I came up with a
circuitous workaround, but can't help but to think that there has to be a
better way. But first, here's what I started with:
template<typename outer_type>
class Outer {
public:
template<typename inner_type>
class Inner {
// …
};
// …
};
So, I'm trying to figure out how to define a specialization for
Inner<outer_type>. That is, a specialization for Inner with the same
typename as its Outer's typename. That is, a specialization for
Outer<int>::Inner<int>, Outer<classname>::Inner<classname>, etc…
g++ appears to compile the following syntax:
template<>
template<typename common_type>
class Outer<common_type>::Inner<common_type> {
// …
};
Yet, it didn't work for me. The following complete example results in the
generic template getting instantiated, and the same output from both
typeid::name() going to std::cout:
==========================================================================
#include <iostream>
#include <typeinfo>
template<typename outer_type>
class Outer {
public:
template<typename inner_type>
class Inner {
public:
Inner()
{
std::cout << "Generic template"
<< std::endl;
std::cout << typeid(outer_type).name() << std::endl;
std::cout << typeid(inner_type).name() << std::endl;
}
~Inner()
{
}
};
};
template<>
template<typename common_type>
class Outer<common_type>::Inner<common_type> {
public:
Inner()
{
std::cout << "Specialized" << std::endl;
}
~Inner()
{
}
};
class C {
};
int main()
{
Outer<C>::Inner<C> n;
}
==========================================================================
So, after beating my head against the wall, I finally came up with the
following solution that solves my immediate problem:
===========================================================================
#include <iostream>
#include <typeinfo>
template<typename outer_type,
typename inner_type> class OuterInner {
public:
OuterInner()
{
std::cout << "Generic template"
<< std::endl;
std::cout << typeid(outer_type).name() << std::endl;
std::cout << typeid(inner_type).name() << std::endl;
}
~OuterInner()
{
}
};
template<>
template<typename common_type>
class OuterInner<common_type, common_type> {
public:
OuterInner()
{
std::cout << "Specialized" << std::endl;
}
~OuterInner()
{
}
};
template<typename outer_type>
class Outer {
public:
template<typename inner_type>
class Inner : public OuterInner<outer_type, inner_type> {
public:
Inner()
{
}
~Inner()
{
}
};
};
class C {
};
int main()
{
Outer<C>::Inner<C> n;
}
===========================================================================
I'd really like to get rid of this extra inheritance, since it complicates
my overall class structure (the above is a minimalized example), and this
means that I'll have to start friending a bunch of stuff, which I'd rather
avoid doing.
==============================================================================
TOPIC: Make Money Rs. 1000 per day My Dear Friends, I tried a lot of works in
online business, finally I find one guniune opportunity. That's www.time2rich.
com/r9a9m9 At www.time2rich.com/r9a9m9 you will have international business,
with just star
http://groups.google.com/group/comp.lang.c++/t/58879de2a25f8654?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 24 2010 9:09 pm
From: kum mia
Make Money Rs. 1000 per day
My Dear Friends,
I tried a lot of works in online business, finally I find one guniune
opportunity. That's
At www.time2rich.com/r9a9m9 you will have international business,
with just starting as low as Rs 350/-!
Your potential income will be Rs 50,000/- Per Month.
Its really a genuine opportunity. Trust Me!!! And if you dont, just
search in any of the search
engines(like google.com/altavista.com...just type in "is time2rich
fraud ?" or similar...you will
get all the reviews..)...
Once you feel comfortable, just click on this link & register.
http://www.time2rich.com/r9a9m9
I am a time2rich member since last month. As a member, I have to show
you how many
members joined in a day and how the scheme is developed. Herewith I
have given details.
(You can see this record in left side, if you press member login
button at
See the scheme developing in three days for example. It is just last
three
days. Think in few days latter. It will grow that we cannot imagine.
Or otherwise, if you have only Rs. 100 spent for this, we have another
opportunity. Just visit www.rich2soon.com/?ref=55
Date : 31.12.2009
Program Info
Active member : 3781
Total payment : Rs 1323350
Member online : 9
Visitor online : 38
Hits today : 3751
Total hits : 948468
Date : 01.01.2010
Program Info
Active member : 3792
Total payment : Rs 1327200
Member online : 13
Visitor online : 20
Hits today : 3523
Total hits : 952311
Date : 02.01.2010
Program Info
Active member : 3814
Total payment : Rs 1334900
Member online : 29
Visitor online : 105
Hits today : 877
Total hits : 957236
All the BEST !!!
Regards,
Ramesh Kumar. S
and also see our ad website
http://123maza.com/50/cricket/
http://123maza.com/50/cricket/
http://123maza.com/50/cricket/
==============================================================================
TOPIC: I'm a newbie. Is this code ugly?
http://groups.google.com/group/comp.lang.c++/t/f085e44989fab5ef?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 24 2010 11:08 pm
From: LR
io_x wrote:
> "LR" <lruss@superlink.net> ha scritto nel messaggio
> news:4b5b359f$0$4831$cc2e38e6@news.uslec.net...
> i'm no the one that ask that question (if i remember all posts)
Oops. Sorry about that.
LR
==============================================================================
TOPIC: ۞۩๑۞۩ HOT Sale AAA True Leather brand handbags: Chanel handbag, Gucci
handbag, LV handbag ect at www.fjrjtrade.com <paypal payment>
http://groups.google.com/group/comp.lang.c++/t/cdc0cab82fb5e01a?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Jan 25 2010 12:10 am
From: "www.fjrjtrade.com"
۞۩๑۞۩ HOT Sale AAA True Leather brand handbags: Chanel handbag, Gucci
handbag, LV handbag ect at www.fjrjtrade.com <paypal payment>
Cheap wholesale handbags www.fjrjtrade.com
Cheap wholesale AAA True Leather handbags www.fjrjtrade.com
Cheap wholesale AAA True Leather handbags
http://www.fjrjtrade.com/1201-AAA-True-Leather.html
Cheap wholesale Burberry Handbags AAA
http://www.fjrjtrade.com/1927-Burberry-Handbags-AAA.html
Cheap wholesale Burberry Purse AAA
http://www.fjrjtrade.com/1928-Burberry-Purse-AAA.html
Cheap wholesale D&G Handbags AAA
http://www.fjrjtrade.com/1943-DG-Handbags-AAA.html
Cheap wholesale Fendi Handbags AAA
http://www.fjrjtrade.com/1929-Fendi-Handbags-AAA.html
Cheap wholesale Hermes Handbags AAA
http://www.fjrjtrade.com/1930-Hermes-Handbags-AAA.html
Cheap wholesale Kooba Handbags AAA
http://www.fjrjtrade.com/1932-Kooba-Handbags-AAA.html
Cheap wholesale Loewe Handbags AAA
http://www.fjrjtrade.com/1933-Loewe-Handbags-AAA.html
Cheap wholesale Marc Jacobs Handbags AAA
http://www.fjrjtrade.com/1934-Marc-Jacobs-Handbags-AAA.html
Cheap wholesale Mulberry Handbags AAA
http://www.fjrjtrade.com/1936-Mulberry-Handbags-AAA.html
Cheap wholesale Prada Handbags AAA
http://www.fjrjtrade.com/1938-Prada-Handbags-AAA.html
Cheap wholesale Thomaswlde Handbags AAA
http://www.fjrjtrade.com/1937-Thomaswlde-Handbags-AAA.html
Cheap wholesale Valentnv Handbags AAA
http://www.fjrjtrade.com/1940-Valentnv-Handbags-AAA.html
Cheap wholesale Versace Handbags AAA
http://www.fjrjtrade.com/1942-Versace-Handbags-AAA.html
Cheap wholesale Balenciaga Handbags AAA
http://www.fjrjtrade.com/1203-Balenciaga-Handbags-AAA.html
Cheap wholesale Balenciaga Purse AAA
http://www.fjrjtrade.com/1204-Balenciaga-Purse-AAA.html
Cheap wholesale Bally Purse AAA
http://www.fjrjtrade.com/1205-Bally-Purse-AAA.html
Cheap wholesale Boss purse AAA
http://www.fjrjtrade.com/1206-Boss-purse-AAA.html
Cheap wholesale Chanel Handbags AAA
http://www.fjrjtrade.com/1207-Chanel-Handbags-AAA.html
Cheap wholesale Chanel Purse AAA
http://www.fjrjtrade.com/1208-Chanel-Purse-AAA.html
Cheap wholesale Chloe Handbags AAA
http://www.fjrjtrade.com/1209-Chloe-Handbags-AAA.html
Cheap wholesale Coach Handbags AAA
http://www.fjrjtrade.com/1211-Coach-Handbags-AAA.html
Cheap wholesale Miumiu Handbags AAA
http://www.fjrjtrade.com/1212-Miumiu-Handbags-AAA.html
Cheap wholesale Dior Handbags AAA
http://www.fjrjtrade.com/1214-Dior-Handbags-AAA.html
Cheap wholesale Gucci Handbags AAA
http://www.fjrjtrade.com/1216-Gucci-Handbags-AAA.html
Cheap wholesale Gucci Purse AAA
http://www.fjrjtrade.com/1217-Gucci-Purse-AAA.html
Cheap wholesale Hermes Purse AAA
http://www.fjrjtrade.com/1218-Hermes-Purse-AAA.html
Cheap wholesale JIMMY CHOO Handbags AAA
http://www.fjrjtrade.com/1219-JIMMY-CHOO-Handbags-AAA.html
Cheap wholesale LV Handbags AAA
http://www.fjrjtrade.com/1221-LV-Handbags-AAA.html
Cheap wholesale LV Purse AAA
http://www.fjrjtrade.com/1222-LV-Purse-AAA.html
More brand items at website:
http://www.fjrjtrade.com
==============================================================================
TOPIC: ☆°ω°☆【Paypal】 Wholesale Cheap Boots brand shoes ( www.ecyaya.com )
http://groups.google.com/group/comp.lang.c++/t/5a36642586151678?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Jan 25 2010 12:11 am
From: hero
☆°ω°☆【Paypal】 Wholesale Cheap Boots brand shoes ( www.ecyaya.com )
Footwear (paypal payment)( www.ecyaya.com )
wholesale DIOR Boots in www.ecyaya.com
wholesale DIOR Sandal in www.ecyaya.com
wholesale Burberry Boots in www.ecyaya.com
wholesale Burberry Sandal in www.ecyaya.com
wholesale Chanel Boots in www.ecyaya.com
wholesale Chanel Sandal in www.ecyaya.com
wholesale COACH Boots in www.ecyaya.com
wholesale COACH Sandal in www.ecyaya.com
wholesale D&G Boots in www.ecyaya.com
wholesale DIOR Boots in www.ecyaya.com
wholesale DIOR Sandal in www.ecyaya.com
wholesale ED Hardy Boots in www.ecyaya.com
wholesale Fendi Boots in www.ecyaya.com
wholesale GUCCI Boots in www.ecyaya.com
wholesale GUCCI Sandal in www.ecyaya.com
wholesale LV Boots in www.ecyaya.com
wholesale LV Sandal in www.ecyaya.com
wholesale UGG Boots Shoes in www.ecyaya.com
wholesale Versace Boots in www.ecyaya.com
Paul Smith shoes (paypal payment)( www.ecyaya.com )
Jordan shoes (paypal payment)( www.ecyaya.com )
Bape shoes (paypal payment)( www.ecyaya.com )
Chanel shoes (paypal payment)( www.ecyaya.com )
D&G shoes (paypal payment)( www.ecyaya.com )
Dior shoes (paypal payment)( www.ecyaya.com )
ED hardy shoes (paypal payment)( www.ecyaya.com )
Evisu shoes (paypal payment)( www.ecyaya.com )
Fendi shoes (paypal payment)( www.ecyaya.com )
Gucci shoe (paypal payment)( www.ecyaya.com )
Hogan shoes (paypal payment)( www.ecyaya.com )
Lv shoes (paypal payment)( www.ecyaya.com )
Prada shoes (paypal payment)( www.ecyaya.com )
Timberland shoes (paypal payment)( www.ecyaya.com )
Tous shoes (paypal payment)( www.ecyaya.com )
Ugg shoes (paypal payment)( www.ecyaya.com )
Ice cream shoes (paypal payment)( www.ecyaya.com )
Sebago shoes (paypal payment)( www.ecyaya.com )
Lacoste shoes (paypal payment)( www.ecyaya.com )
Air force one shoes (paypal payment)( www.ecyaya.com )
TODS shoes (paypal payment)( www.ecyaya.com )
AF shoes (paypal payment)( www.ecyaya.com )
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
No comments:
Post a Comment