Monday, January 25, 2010

comp.lang.c++ - 25 new messages in 14 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* ☆°ω°☆【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
* Default constructor and const - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/bba6f596896f5533?hl=en
* Type of elements of std::string - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/b6aba4785e69df38?hl=en
* How to identify the exe file associated with core dump - 4 messages, 4
authors
http://groups.google.com/group/comp.lang.c++/t/ae385d53872a2543?hl=en
* u_char and pointers - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/eba6f130a451ed40?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
* Object (de)serialization - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/9fc67e8f28fe4918?hl=en
* size_t Question - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/d04eb033c399a55c?hl=en
* C++ function argument with 'class' keyword? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/f43dbb9087b23386?hl=en
* EXC_BAD_ACCESS during Copy Constructor - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/4df988891eedf2bd?hl=en
* ❤◆◆◆❤ <Paypal Payment> Cheap Wholesale Chanel shoes at www.fjrjtrade.com - 1
messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/3150c8adcc9eed9f?hl=en
* bounded buffer - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/89e05f4408614915?hl=en
* Best way to delete contents of a list list of (pointers) - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/4c91a5efee60ad8d?hl=en
* memory leaks - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/d9b20823062f2cb3?hl=en

==============================================================================
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 )

==============================================================================
TOPIC: Default constructor and const
http://groups.google.com/group/comp.lang.c++/t/bba6f596896f5533?hl=en
==============================================================================

== 1 of 3 ==
Date: Mon, Jan 25 2010 1:36 am
From: mathieu


On Jan 24, 1:56 am, Branimir Maksimovic <bm...@hotmail.com> wrote:
> James Kanze wrote:
> > On Jan 23, 6:19 pm, Yu Han <hanju...@163.com> wrote:
> >>> In this case I think I found a bug in g++4.5:
>
> >>> struct A
> >>> {
> >>>    A(){}
> >>> };
>
> >>> struct B : public A
> >>> {
> >>> };
>
> >>> int main()
> >>> {
> >>>    const B b;
> >>>    return 0;
> >>> }
>
> >> What bug?
>
> > FWIW: if memory serves me correctly, even something like:
>
> >     struct A{};
> >     A const a;
>
> > requires a diagnostic.
>
> Comeau online says error, it reqires default constructor or initializer
>   while g++ 4.4.1 compiles without warning or error even with -std=c++98
> -pedantic -Wall
>
> In case of struct A{}; A const a;
> g++ gives error about non initialized constant.

Exactly what I am having here. This has been logged as:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42844

Cheers


== 2 of 3 ==
Date: Mon, Jan 25 2010 1:48 am
From: Vladimir Jovic


Alf P. Steinbach wrote:
> * mathieu:
>> Hi there,
>>
>> Could someone let me know why Comeau reports an error on the
>> following code. The compiler should provide a default constuctor for
>> me.
>>
>> struct A { int I; };
>> int main()
>> {
>> const A a;
>> return 0;
>> }
>>
>> Thanks !
>>
>> Output:
>> Comeau C/C++ 4.3.9 (Mar 27 2007 17:24:47) for ONLINE_EVALUATION_BETA2
>> Copyright 1988-2007 Comeau Computing. All rights reserved.
>> MODE:strict errors C++ noC++0x_extensions
>>
>> "ComeauTest.c", line 8: error: const variable "a" requires an
>> initializer -- class
>> "A" has no explicitly declared default constructor
>> const A a;
>> ^
>>
>> "ComeauTest.c", line 8: warning: variable "a" was declared but never
>> referenced
>> const A a;
>> ^
>>
>> 1 error detected in the compilation of "ComeauTest.c".
>
> The C++ rules amount to this: that a constant's value must be explicitly
> specified in some way.

In this case, like this :

struct A { int I; };
int main()
{
const A a = { 3 };
}

>
> Explicitly defining a default constructor is one way.
>

Not if it is a POD.


== 3 of 3 ==
Date: Mon, Jan 25 2010 4:42 am
From: "Alf P. Steinbach"


* Vladimir Jovic:
> Alf P. Steinbach wrote:
>> * mathieu:
>>> Hi there,
>>>
>>> Could someone let me know why Comeau reports an error on the
>>> following code. The compiler should provide a default constuctor for
>>> me.
>>>
>>> struct A { int I; };
>>> int main()
>>> {
>>> const A a;
>>> return 0;
>>> }
>>>
>>> Thanks !
>>>
>>> Output:
>>> Comeau C/C++ 4.3.9 (Mar 27 2007 17:24:47) for ONLINE_EVALUATION_BETA2
>>> Copyright 1988-2007 Comeau Computing. All rights reserved.
>>> MODE:strict errors C++ noC++0x_extensions
>>>
>>> "ComeauTest.c", line 8: error: const variable "a" requires an
>>> initializer -- class
>>> "A" has no explicitly declared default constructor
>>> const A a;
>>> ^
>>>
>>> "ComeauTest.c", line 8: warning: variable "a" was declared but never
>>> referenced
>>> const A a;
>>> ^
>>>
>>> 1 error detected in the compilation of "ComeauTest.c".
>>
>> The C++ rules amount to this: that a constant's value must be
>> explicitly specified in some way.
>
> In this case, like this :
>
> struct A { int I; };

OK, it's just repeating the OP's struct definition, but as a general rule, don't
use all uppercase names for anything but macros, except where they're idiomatic
(as in a template parameter T).


> int main()
> {
> const A a = { 3 };
> }

Usually there isn't just one way to do something.

For example,

A x; // Statically initialized to zero
int main()
{
A const a = x;
}

or

int main()
{
A const a = A();
}

Or one might get more elaborate and use a function returning an A, with that
function e.g. constructing an A from raw bytes.


>> Explicitly defining a default constructor is one way.
>>
>
> Not if it is a POD.

I think you mean, not if it is required to be a POD. ;-)


Cheers & hth.,

- Alf

==============================================================================
TOPIC: Type of elements of std::string
http://groups.google.com/group/comp.lang.c++/t/b6aba4785e69df38?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Jan 25 2010 1:51 am
From: Leslaw Bieniasz

Hi,

What is actually the type of elements of std::string?

I am trying to read the elements from a stream, in the following
way:

std::string str = "";
int c;

// Read string size
int n;
is >> n;

// Read string
for(int i=0; i<n; i++)
{
c = is.get();
str += c;
}

This seems to work, but the compiler (C++ Builder 6.0)
issues a warning at
c = is.get();
The warning is: Conversion may lose significant digits

On the other hand, if I switch to "char" instead of "int"
it seems that the code does not work.

How to write the code that does exactly the same thing
but without the warning?

Leslaw


== 2 of 4 ==
Date: Mon, Jan 25 2010 2:25 am
From: Richard Herring


In message <Pine.GHP.4.64.1001251045190.17688@kinga.cyf-kr.edu.pl>,
Leslaw Bieniasz <nbbienia@cyf-kr.edu.pl> writes
>
>Hi,
>
>What is actually the type of elements of std::string?

char.

>
>I am trying to read the elements from a stream, in the following
>way:
>
>std::string str = "";
>int c;
>
>// Read string size
>int n;
>is >> n;
>
>// Read string
>for(int i=0; i<n; i++)
> {
> c = is.get();
> str += c;
> }
>
>This seems to work, but the compiler (C++ Builder 6.0)
>issues a warning at
>c = is.get();
>The warning is: Conversion may lose significant digits

Are you sure the warning isn't at the following line? std::string
doesn't have an operator+= which takes an int, and int to char is a
conversion that might lose significance.

>
>On the other hand, if I switch to "char" instead of "int"
>it seems that the code does not work.

What do you mean by "does not work"?
>
>How to write the code that does exactly the same thing
>but without the warning?
>
Understand how istream::get() reports errors.

--
Richard Herring


== 3 of 4 ==
Date: Mon, Jan 25 2010 3:29 am
From: Leslaw Bieniasz


On Mon, 25 Jan 2010, Richard Herring wrote:

> Are you sure the warning isn't at the following line? std::string doesn't
> have an operator+= which takes an int, and int to char is a conversion that
> might lose significance.

Well, I understand that, but the essential question is how to read
the elements of std::string correctly, if std::string contains char,
whereas get() returns int. This looks like some sort of incompatibility.
>>
> Understand how istream::get() reports errors.

Surely I am not asking how to cheat the compiler to not to get messages,
but how to do things correctly.

Leslaw


== 4 of 4 ==
Date: Mon, Jan 25 2010 3:57 am
From: Richard Herring


In message <Pine.GHP.4.64.1001251223490.12454@kinga.cyf-kr.edu.pl>,
Leslaw Bieniasz <nbbienia@cyf-kr.edu.pl> writes
>On Mon, 25 Jan 2010, Richard Herring wrote:
>
>> Are you sure the warning isn't at the following line? std::string
>>doesn't have an operator+= which takes an int, and int to char is a
>>conversion that might lose significance.
>
>Well, I understand that, but the essential question is how to read
>the elements of std::string correctly, if std::string contains char,
>whereas get() returns int. This looks like some sort of incompatibility.

Do you understand *why* get() returns int, and what subset of possible
int values it can return? That's the point of my question below:

>>>
>> Understand how istream::get() reports errors.
>
>Surely I am not asking how to cheat the compiler to not to get messages,
>but how to do things correctly.
>
Good. Then you should be reading an int from get(), separating out the
values that represent characters from those which don't, appending the
chars to the string and doing something else with the non-chars.

--
Richard Herring

==============================================================================
TOPIC: How to identify the exe file associated with core dump
http://groups.google.com/group/comp.lang.c++/t/ae385d53872a2543?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Jan 25 2010 1:54 am
From: mthread


Hi,
We have multiple applications(C & C++) running in our system. When
a core dump is generated we did not know which application caused the
core dump. Is there a way to find the application name from the core
dump file. Kindly help me on this issue.


== 2 of 4 ==
Date: Mon, Jan 25 2010 2:26 am
From: Philip Pemberton


On Mon, 25 Jan 2010 01:54:26 -0800, mthread wrote:

> Hi,
> We have multiple applications(C & C++) running in our system. When
> a core dump is generated we did not know which application caused the
> core dump. Is there a way to find the application name from the core
> dump file. Kindly help me on this issue.

Assuming this is on a *nix system of some description:
$ file core

Or possibly:
$ gdb core

(But this is more an OS-specific question, not a C++ question)


== 3 of 4 ==
Date: Mon, Jan 25 2010 2:29 am
From: Vladimir Jovic


mthread wrote:
> Hi,
> We have multiple applications(C & C++) running in our system. When
> a core dump is generated we did not know which application caused the
> core dump. Is there a way to find the application name from the core
> dump file. Kindly help me on this issue.

See this:
http://www.sinz.org/Michael.Sinz/Linux/core.html


btw you are off topic here


== 4 of 4 ==
Date: Mon, Jan 25 2010 2:27 am
From: Richard Herring


In message
<41bbc3e2-fde8-431d-b065-fc0782b62333@g29g2000yqe.googlegroups.com>,
mthread <rjkumr@gmail.com> writes
>Hi,
> We have multiple applications(C & C++) running in our system. When
>a core dump is generated we did not know which application caused the
>core dump. Is there a way to find the application name from the core
>dump file. Kindly help me on this issue.
>
This has nothing to do with C++ (or C): your question would be identical
if the applications were written in Fortran or COBOL.. You're more
likely to get a useful response by asking in a newsgroup that deals with
your particular operating system.

--
Richard Herring

==============================================================================
TOPIC: u_char and pointers
http://groups.google.com/group/comp.lang.c++/t/eba6f130a451ed40?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 2:11 am
From: Richard Herring


In message
<8b9ca791-d5c2-47cb-85ce-1f9458b7fd16@a6g2000yqm.googlegroups.com>,
Nilbert Nullingsworth <yakahughes@gmail.com> writes
>Actually it works fine by doing something like this for example:
>
>char* source = "asdf";
>
>u_char* dest = new u_char[len];
>
>for (int i = 0; i < len; i++) {
> dest[i] = source[i];
>}
>
>Is it better to use a vector?

Yes. Using std::vector means you don't have to worry about the delete[]
which is missing from your code above.

std::vector<char> dest(source, source+strlen(source));

--
Richard Herring

==============================================================================
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: Mon, Jan 25 2010 2:12 am
From: Richard Herring


In message <4b5b5b92$0$1101$4fafbaef@reader4.news.tin.it>, io_x
<a@b.c.invalid> writes
>
>"Richard Herring" <junk@[127.0.0.1]> ha scritto nel messaggio
>news:KJlK$0BNjXWLFw2x@baesystems.com...
>> In message <4b594ee2$0$1115$4fafbaef@reader4.news.tin.it>, io_x
>> <a@b.c.invalid> writes
>>>>>>>{int i, n;
>>>>>>> char *p;
>>>>>>> if(v==0) R 0;
>>>>>>> n=strlen(v);
>>>>>>> if(n<=0) R 0;
>>>>>>
>>>>>> Why? There's nothing intrinsically wrong with a zero-length string.
>>>>>
>>>>>yes here i would say "if(n<0) R 0;"
>>>>
>>>> And under what circumstances would strlen() ever return a negative value?
>>>
>>>it seems strlen() here returned one unsigned type: size_t
>>>here size_t is "unsigned int" of 32 bit but this means
>>>strlen can return 0xF0000000 that is a negative number
>>>seen it like int;
>>
>> Only because you are perversely choosing to cast it to a signed type when it
>> is not.
>
>>>and for me that negative number is not ok
>>
>> So you should be declaring the variable n as size_t, not int.
>
>i choose int
>so i choose that the valid array of chars
>could have len in the range 0..max_int
>at last here in my sys
>
Not a valid reason. By that logic, if you chose double, you could have
lengths up to DBL_MAX.

Why do you have a problem with giving n the obvious type (because it is
what strlen returns) of size_t? What do you think the length range would
be in that case?

--
Richard Herring

==============================================================================
TOPIC: Object (de)serialization
http://groups.google.com/group/comp.lang.c++/t/9fc67e8f28fe4918?hl=en
==============================================================================

== 1 of 3 ==
Date: Mon, Jan 25 2010 2:25 am
From: Philip Pemberton


Hi guys,
I'm trying to write the contents of a set of classes to a file in a
reasonably portable way. Obviously I also want to be able to read the
files back into memory later on. At this point, my serializer works fine;
I can create an object (or several objects) and save them to a file. Now
I need to get them back out of the file...

I've been reading the C++ FAQ (notably Section 36, Serialization and
Unserialization) and I've been writing small prototype apps to try and
learn how all this stuff works. I came up with this, based on the textual
description in C++ FAQ 36.8:

#include <map>
#include <string>
#include <iostream>

using namespace std;

class Shape {
public:
Shape() { cerr<<"ctor: Shape\n"; };
static std::map<std::string, Shape *> creationMap;
virtual Shape *create(string data) const =0;
virtual string getType() const =0;
static Shape *deserialise(string data) {
return creationMap[data]->create(data);
}
};

class Triangle : public Shape {
public:
Triangle() {
cerr<<"ctor: Triangle\n";
creationMap["triangle"] = new Triangle();
}
virtual Shape *create(string data) const {
if (creationMap.count(data) == 0) throw -1;
return new Triangle();
}
virtual string getType() const {return "triangle";}
};

int main(void)
{
Shape *x = Shape::deserialise("triangle");

return 0;
}

This looks fine to me, and it compiles -- but it won't link:
philpem@cougar:~/dev$ g++ -o test test.cpp && ./test
/tmp/ccDHDpxd.o: In function `Shape::deserialise(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >)':
test.cpp:(.text._ZN5Shape11deserialiseESs[Shape::deserialise
(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]
+0x12): undefined reference to `Shape::creationMap'
collect2: ld returned 1 exit status

Compiler is g++ (gcc) 4.4.1-4ubuntu8, on Ubuntu Linux 9.10 (32-bit).

Can anyone see what I'm doing wrong here? I'm sure it's blatantly obvious
to an experienced developer, but this is the first time I've tried to
implement something like this, and I'm really not having much luck...

Thanks,
Phil.


== 2 of 3 ==
Date: Mon, Jan 25 2010 2:55 am
From: Richard Herring


In message <002b5892$0$30072$c3e8da3@news.astraweb.com>, Philip
Pemberton <usenet09@philpem.me.uk> writes
>Hi guys,

Your subject line is wrong: try something more like "linker complains
about missing static class member" ;-)

>I'm trying to write the contents of a set of classes to a file in a
>reasonably portable way. Obviously I also want to be able to read the
>files back into memory later on. At this point, my serializer works fine;
>I can create an object (or several objects) and save them to a file. Now
>I need to get them back out of the file...
>
>I've been reading the C++ FAQ (notably Section 36, Serialization and
>Unserialization) and I've been writing small prototype apps to try and
>learn how all this stuff works. I came up with this, based on the textual
>description in C++ FAQ 36.8:
>
>#include <map>
>#include <string>
>#include <iostream>
>
>using namespace std;
>
>class Shape {
> public:
> Shape() { cerr<<"ctor: Shape\n"; };
> static std::map<std::string, Shape *> creationMap;

That's a declaration. Where's the corresponding definition?

std::map<std::string, Shape *> Shape::creationMap;

(hint: if this is shape.h it probably ought to be in shape.cpp)

> virtual Shape *create(string data) const =0;
> virtual string getType() const =0;
> static Shape *deserialise(string data) {
> return creationMap[data]->create(data);
> }
>};
>

[...]

>
>This looks fine to me, and it compiles -- but it won't link:
>philpem@cougar:~/dev$ g++ -o test test.cpp && ./test
>/tmp/ccDHDpxd.o: In function `Shape::deserialise(std::basic_string<char,
>std::char_traits<char>, std::allocator<char> >)':
>test.cpp:(.text._ZN5Shape11deserialiseESs[Shape::deserialise
>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]
>+0x12): undefined reference to `Shape::creationMap'

Confirmation: there's no definition of Shape::creationMap.

>collect2: ld returned 1 exit status

--
Richard Herring


== 3 of 3 ==
Date: Mon, Jan 25 2010 5:13 am
From: Brian


On Jan 25, 4:25 am, Philip Pemberton <usene...@philpem.me.uk> wrote:
> Hi guys,
> I'm trying to write the contents of a set of classes to a file in a
> reasonably portable way. Obviously I also want to be able to read the
> files back into memory later on. At this point, my serializer works fine;
> I can create an object (or several objects) and save them to a file. Now
> I need to get them back out of the file...
>
> I've been reading the C++ FAQ (notably Section 36, Serialization and
> Unserialization) and I've been writing small prototype apps to try and
> learn how all this stuff works. I came up with this, based on the textual
> description in C++ FAQ 36.8:
>
> #include <map>
> #include <string>
> #include <iostream>
>
> using namespace std;
>
> class Shape {
>         public:
>                 Shape() { cerr<<"ctor: Shape\n"; };
>                 static std::map<std::string, Shape *> creationMap;
>                 virtual Shape *create(string data) const =0;
>                 virtual string getType() const =0;
>                 static Shape *deserialise(string data) {
>                         return creationMap[data]->create(data);
>                 }
>
> };
>
> class Triangle : public Shape {
>         public:
>                 Triangle() {
>                         cerr<<"ctor: Triangle\n";
>                         creationMap["triangle"] = new Triangle();
>                 }

That default constructor looks like trouble. Perhaps you
could move the second line to another function.


Brian Wood
http://webEbenezer.net
(651) 251-9384

==============================================================================
TOPIC: size_t Question
http://groups.google.com/group/comp.lang.c++/t/d04eb033c399a55c?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 2:37 am
From: Richard Herring


In message
<8d88539d-ac35-45a4-bdd3-9ebdc5023165@p24g2000yqm.googlegroups.com>,
Immortal Nephi <Immortal_Nephi@hotmail.com> writes

> You cannot use
>size_t if you want to store it into array, but you use char, int, or
>long instead.

What?

You can have arrays (and indeed vectors and lists and dequeues and sets
and ...) of size_t just as you can of any other integral type.

--
Richard Herring

==============================================================================
TOPIC: C++ function argument with 'class' keyword?
http://groups.google.com/group/comp.lang.c++/t/f43dbb9087b23386?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 3:51 am
From: Pete Becker


James Kanze wrote:
> 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.
>

I hate it when I do that. <g>

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

==============================================================================
TOPIC: EXC_BAD_ACCESS during Copy Constructor
http://groups.google.com/group/comp.lang.c++/t/4df988891eedf2bd?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 4:59 am
From: Philip Lee Bridson


On Jan 24, 11:45 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> 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

Thanks all for the advice. Your posts were very helpful. I understand
why I was going wrong now and I will ammend the lines that are causing
the issue. Kind Regards, Phil.

==============================================================================
TOPIC: ❤◆◆◆❤ <Paypal Payment> Cheap Wholesale Chanel shoes at www.fjrjtrade.
com
http://groups.google.com/group/comp.lang.c++/t/3150c8adcc9eed9f?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 5:49 am
From: "www.fjrjtrade.com"


❤◆◆◆❤ <Paypal Payment> Cheap Wholesale Chanel shoes at www.fjrjtrade.com


Welcome to visit www.fjrjtrade.com

Men size 40,41,42,43,44,45,46. Women size 36,37,38,39,40.

High quality wholesale Air Force One shoes, Nike Jordan, Nike,Air Max,
Nike Shox, Puma Shoes, Nike shoes, Adidas Shoes, Christian Louboutin,
Chanel Shoes, Coach Shoes, D&G Shoes, Dior Shoes, ED Hardy Shoes,
Evisu Shoes, Fendi Shoes, AFF shoes, Bape shoes, Gucci Shoes, Hogan
shoes, Bikkembergs Shoes, Dsquared Shoes, LV Shoes, Timberland Shoes,
Boss shoes, Versace Shoes, Prada Shoes, Lacoste Shoes, Mauri Shoes, DC
shoes ect. Details at website www.fjrjtrade.com

Cheap wholesale shoes

www.fjrjtrade.com

Cheap wholesale Chanel shoes

www.fjrjtrade.com

Cheap wholesale Chanel shoes

http://www.fjrjtrade.com/926-Chanel-Shoes.html

Cheap Wholesale Chanel Boots

http://www.fjrjtrade.com/1862-Chanel-Boots.html

Cheap Wholesale Chanel Women shoes

http://www.fjrjtrade.com/1863-Chanel-Shoes-Women.html

Cheap Wholesale Chanel shoes Women Mid

http://www.fjrjtrade.com/1864-Chanel-Shoes-Women-Mid.html

More models at website:
http://www.fjrjtrade.com

==============================================================================
TOPIC: bounded buffer
http://groups.google.com/group/comp.lang.c++/t/89e05f4408614915?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 7:00 am
From: "Larry"


"Yu Han" <hanjunyu@163.com> ha scritto nel messaggio
news:hjhjus$1ddr$1@adenine.netfront.net...

> Maybe a circular buffer is better, maybe...

Do you think the following could be fine approach?

// declare
typedef unsigned int regkey;
typedef struct {...} buffer;

// global buffer
std::map<regkey, buffer> clients

// a client connect (add consumer)
clients.insert(makepair(regkey, buffer));

// a client disconnect (remove comsumer)
clients.remove(regkey);

// Producer writes to every element in the map(clients)
(...)

thanks


==============================================================================
TOPIC: Best way to delete contents of a list list of (pointers)
http://groups.google.com/group/comp.lang.c++/t/4c91a5efee60ad8d?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 7:00 am
From: ytrembla@nyx.nyx.net (Yannick Tremblay)


In article <hjcgl1$dra$1@news.datemas.de>,
Victor Bazarov <v.Abazarov@comAcast.net> wrote:
>Yannick Tremblay wrote:
>> In article <54632acd-653b-4602-b611-6c7741ad7217@a15g2000yqm.googlegroups.com>,
>> Angus <anguscomber@gmail.com> wrote:
>>> m_contacts is a std::list<myobject>.
>>
>> I'll assume the missing * is a mistake here?
>>
>> However, this is quite relevant and maybe the correct answer is that
>> it shouldn't be a mistake.
>>
>> m_contacts is a private list of myobjects that belong to a class.
>> Either the individual myobjects belong to the class, in this case the
>> class can destroy them, or they don't and the class can't destroy
>> them.
>>
>> If the collection fully belong to the class, then you may as well use
>> a std::list<myobject> instead of a std::list<myobject*> and your
>> problem is gone.
>
>Not if the actual objects created using 'new' are polymorphic (of types
>that are descendants of 'myobject').

Agree.

But in that case, the OP could use a simple STL compatible smart pointer.

Unfortunately, in a lot of case, some_stl_container<object *> tend to
be a misguided attempt at saving copies or a misunderstanding of why
the STL uses copy semantic (or maybe I should say a refusal to
understand or accept)

Yannick

==============================================================================
TOPIC: memory leaks
http://groups.google.com/group/comp.lang.c++/t/d9b20823062f2cb3?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Jan 25 2010 8:01 am
From: "Larry"


Hi,

do you think the following code could lead to memory leaks? it creates a
circualr buffer made up of 5 element then it pushes 10 elements (overwriting
the first 5) when overwriting , do you think the eldest pointed memory will
be overwritten, or a new pointer in memory will be written?

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <boost/circular_buffer.hpp>
using namespace std;
using namespace boost;

char * getDateTime(void);
const short numbuff = 5;
const short buflen = 30;

typedef struct
{
unsigned char * pData;
unsigned short bufferLength;
unsigned short bytesRecorded;
bool flag;
} Buffer;

int main()
{
circular_buffer<Buffer*> cb(numbuff);
circular_buffer<Buffer*>::const_iterator it;

printf("Push elements:\n");
// fill buffer
for(int i = 0; i<10; i++)
{
// set up buffer
Buffer *buff = new Buffer;
ZeroMemory(buff, sizeof(Buffer));

buff->bufferLength = buflen;
buff->bytesRecorded = buflen;
buff->flag = true;
buff->pData = new unsigned char[buflen];
buff->pData = reinterpret_cast<unsigned char *>(getDateTime());

printf("%s\n", buff->pData);

// push buffer
cb.push_back(buff);

Sleep(1000);
}

printf("\nShow elements:\n");

// show elements
for(int i = 0; i<static_cast<int>(cb.size()); i++)
{
printf("%s\n", cb[i]->pData);
}

system("pause");
return EXIT_SUCCESS;
}

// getDateTime (Fri, 10 Oct 2008 14:41:59 GMT)
char * getDateTime(void)
{
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = gmtime(&rawtime);
char * buffer = new char[30];
strftime(buffer,30,"%a, %d %b %Y %X GMT",timeinfo);
return buffer;
}

// thanks

== 2 of 2 ==
Date: Mon, Jan 25 2010 8:14 am
From: "Alf P. Steinbach"


* Larry:
> Hi,
>
> do you think the following code could lead to memory leaks? it creates
> a circualr buffer made up of 5 element then it pushes 10 elements
> (overwriting the first 5) when overwriting , do you think the eldest
> pointed memory will be overwritten, or a new pointer in memory will be
> written?

The question is unclear, but yes, you have memory leaks.

The memory leaks are due to coding at the C level.

In C++ use library classes, such as replacing your Buffer with std::string. :-)

> #define _CRT_SECURE_NO_WARNINGS

Don't do that.


> #include <windows.h>
> #include <vector>
> #include <cstdlib>
> #include <ctime>
> #include <cstdio>
> #include <boost/circular_buffer.hpp>
> using namespace std;
> using namespace boost;
>
> char * getDateTime(void);

Let that function return std::string.

By the way, 'void' as argument type is a C-ism.

It doesn't make much sense in C++.


> const short numbuff = 5;
> const short buflen = 30;

This confuses two different kinds of buffers: your circular buffer with room for
5 strings, and your string type named "Buffer" with room for 30 characters.

You don't need the latter constant.

For the first constant, consider replacing 'short' with 'int': there's no good
reason to choose anything but 'int' here.


> typedef struct
> {
> unsigned char * pData;
> unsigned short bufferLength;
> unsigned short bytesRecorded;
> bool flag;
> } Buffer;

Just remove that.


> int main()
> {
> circular_buffer<Buffer*> cb(numbuff);

This would be

circular_buffer<string> timeStrings( bufferSize );


> circular_buffer<Buffer*>::const_iterator it;
>
> printf("Push elements:\n");
> // fill buffer
> for(int i = 0; i<10; i++)
> {
> // set up buffer
> Buffer *buff = new Buffer;
> ZeroMemory(buff, sizeof(Buffer));
>
> buff->bufferLength = buflen;
> buff->bytesRecorded = buflen;
> buff->flag = true;
> buff->pData = new unsigned char[buflen];
> buff->pData = reinterpret_cast<unsigned char *>(getDateTime());

Don't cast.

>
> printf("%s\n", buff->pData);
>
> // push buffer
> cb.push_back(buff);

This would be simply

timeStrings.push_back( getDateTime() );


> Sleep(1000);
> }
>
> printf("\nShow elements:\n");
>
> // show elements
> for(int i = 0; i<static_cast<int>(cb.size()); i++)
> {
> printf("%s\n", cb[i]->pData);
> }
>
> system("pause");
> return EXIT_SUCCESS;
> }
>
> // getDateTime (Fri, 10 Oct 2008 14:41:59 GMT)
> char * getDateTime(void)
> {
> time_t rawtime;
> struct tm * timeinfo;
> time(&rawtime);
> timeinfo = gmtime(&rawtime);
> char * buffer = new char[30];
> strftime(buffer,30,"%a, %d %b %Y %X GMT",timeinfo);
> return buffer;
> }

See above.


Cheers & hth.,

- Alf


==============================================================================

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: