Thursday, October 30, 2008

26 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:

* Is c++ only better c ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/38527e42967dc124?hl=en
* VC++: Trying to change taskbar icons using notifyIcon1 and imageList1 - 2
messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/642324bf45818686?hl=en
* Question about creating a struct of flags in c++ - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aded373b78039bdf?hl=en
* Class objects work like built-in types, but is it worth it? - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/2c47abdc653f2dd1?hl=en
* User defined class meta data (type traits?) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/f1c011020110c357?hl=en
* Why I can't get the correct result - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/77454825337d9113?hl=en
* const correctness - should C++ prefer const member over non-const? - 6
messages, 3 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/35cc955f55ea7387?hl=en
* List erase iterator outside range - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/25a39eff0031f895?hl=en
* Replace _T() macros - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/8db5322ba522aa5d?hl=en
* Dealing with a Diamond of Death - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/23939507fa6eb9c8?hl=en
* Strooustrup - Hello World exercise - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/082118a58f35476a?hl=en
* copy from keys from multimap into the vector - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/abc66612050d5014?hl=en
* Understanding branches within destructors - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/941d5fdc87309f38?hl=en
* Download free IT and Computer Projects - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/564ea41b8850d3c4?hl=en

==============================================================================
TOPIC: Is c++ only better c ?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/38527e42967dc124?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Oct 30 2008 12:07 am
From: Ian Collins


Juha Nieminen wrote:
> James Kanze wrote:
>>> As an example of what I'm talking about, consider MathML vs.
>>> LaTeX equations, and which one is easier for a human to
>>> write.)
>> Neither are, IMHO, particularly simple.
>
> I didn't ask if either one is particularly simple. I asked which one
> is *simpler* for a human to write (and read).
>
> The LaTeX equation syntax is *by far* simpler to read and write by a
> human.

The verbosity id largely irrelevant, most of the XML I deal with (which
is a lot) is generated by machines to communicate between machines or
generated by humans as source for generating other formats.

XML should not be considered in isolation, but in the context of the
tools that work with it (CSS, DOM, XSLT and friends).

--
Ian Collins


==============================================================================
TOPIC: VC++: Trying to change taskbar icons using notifyIcon1 and imageList1
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/642324bf45818686?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Oct 30 2008 12:36 am
From: bahnfire


Hi,

I am using Visual C++ Express 2008 and am trying to change the taskbar
icon that I am using (notifyIcon1) as some state changes (button
press, etc) in my form/app. I have read that I can use imageList1 and
have the following:

//
// notifyIcon1
//
this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^
>(resources->GetObject(L"notifyIcon1.Icon")));

this->notifyIcon1->Text = L"Right-click to access";
this->notifyIcon1->Visible = true;

//
// imageList1
//
this->imageList1->ImageStream =
(cli::safe_cast<System::Windows::Forms::ImageListStreamer^
>(resources->GetObject(L"imageList1.ImageStream")));

this->imageList1->TransparentColor =
System::Drawing::Color::Transparent;
this->imageList1->Images->SetKeyName(0, L"one.ico");
this->imageList1->Images->SetKeyName(1, L"two.ico");
this->imageList1->Images->SetKeyName(2, L"three.ico");
this->imageList1->Images->SetKeyName(3, L"g=four.ico");
this->imageList1->Images->SetKeyName(4, L"five.ico");

I have read that I am supposed to use the following 'notifyIcon1->Icon
= Icon->FromHandle();', but all of the examples that I have seen are
for VB and VC#.

I would appreciate any help.

Thanks!

== 2 of 2 ==
Date: Thurs, Oct 30 2008 1:30 am
From: Ian Collins


bahnfire wrote:
> Hi,
>
> I am using Visual C++ Express 2008 and am trying to change the taskbar
> icon

Then you should ask on a windows group rather than here.

--
Ian Collins


==============================================================================
TOPIC: Question about creating a struct of flags in c++
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/aded373b78039bdf?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Oct 30 2008 1:07 am
From: Hisense


On 10月30日, 下午1时50分, "Plisske...@gmail.com" <Plisske...@gmail.com>
wrote:
> On Oct 29, 11:10 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
>
>
>
>
>
> > Plisske...@gmail.com wrote:
> > > Is there an efficient way to create a struct of flag in C++?
>
> > > I need to create a struct of boolean flag, like this:
> > > struct testStruct {
> > > bool flag1;
> > > bool flag2;
> > > bool flag3;
> > > bool flag4;
> > > bool flag5;
> > > bool flag6;
> > > bool flag7;
> > > bool flag8;
> > > bool flag9;
> > > bool flag10;
> > > bool flag11;
> > > bool flag12;
> > > bool flag13;
> > > };
>
> > > But if I do that, i print out the sizeof(), that struct and it is 13.
> > > So i think the compile use 1 byte for each flag.
>
> > > Is it possible to create a struct so that each flag uses only 1 bit.
>
> > Yes, read about bitfields. The syntax is the colon and the field width
> > after the name of the member, like
>
> > bool flag1:1;
>
> > V
> > --
> > Please remove capital 'A's when replying by e-mail
> > I do not respond to top-posted replies, please don't ask
>
> Thank you Victor.
>
> I am going to follow you suggestion. If I create a class like this:
> class myMask {
> public:
> bool flag1:1;
> bool flag2:1;
> bool flag3:1;
> bool flag4:1;
> bool flag5:1;
> bool flag6:1;
> bool flag7:1;
> bool flag8:1;
> bool flag9:1;
> bool flag10:1;
> bool flag11:1;
> bool flag12:1;
> bool flag13:1;
> };
>
> Can I set all the flag to 0 by doing this:
>
> myMask mask;
>
> memset(&mask, '\0', sizeof(myMask));
>
> And can I compare if 2 masks are the same by doing this:
>
> myMask mask1;
> myMask mask2;
>
> memcmp(&mask1, &mask2, sizeof(myMask));
>
> Thanks.- 隐藏被引用文字 -
>
> - 显示引用的文字 -

there are two things to say:
1, you need no class, but struct, because struct is good enough to
solve it;
2, either class or struct, you could use ctor where all the bit fields
are set to 0 or any value you want.


==============================================================================
TOPIC: Class objects work like built-in types, but is it worth it?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/2c47abdc653f2dd1?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Oct 30 2008 1:07 am
From: Paavo Helde


tonytech08 <tonytech08@gmail.com> kirjutas:

> On Oct 29, 3:07 am, Paavo Helde <nob...@ebi.ee> wrote:
>> tonytech08 <tonytec...@gmail.com> kirjutas:
>>
>>
>>
>> > When would you _ever_ want to use containers with value semantics
>> > other than
>> > with pointers to objects?
>>
>> Basically whenever when the objects are not polymorphic. Using
pointers
>> instead of objects themselves adds a level of indirection with its own
>> complexity and problems, this should be avoided when not needed.
>
> We'll have to agree to disagree on that.
>
>>
>>
>>
>> > Well the container topic got backed into here. The issue of this
>> > thread are
>> > class objects. Using a container (STL) with value sematics for a
>> > object of
>> > class type imposes unnecessary requirements on the class.
>>
>> Nah, you still have it backwards; if the class supports value
semantics
>> one can have value-based containers of the objects (with simplified
>> semantics), *in addition* to pointer-based containers, which are still
>> there.
>
> We'll have to agree to disagree on that also.
>
>>
>>
>>
>> > A point is that exceptions and constructors are pretty much a
package
>> > deal because the alternatives are ugly.
>>
>> It appears you are claiming that if there are two good features
fitting
>> nicely with each other, they should be both banned, for unfair
>> competition ;-)
>
> Nothing like that.
>
> One things I'd miss if there wasn't class objects that behave like
> built-in types are those objects you can code up to do something like
> release a lock no matter how the enclosing scope gets exited. What are
> those things called? I'd probably be satisfied with only one of those
> things though that I could wrap around other objects to get the same
> effect.

It seems that what you want is some kind of scripting language. At least
the scripting language developed by our company fulfills almost all
criteria. It has no means for defining new data types, so all types are
built-in. The built-in types include things like Image, Table and
Container. There are no script-defined constructors or destructors. There
is no pointer type. In the script everything looks value-based, but under
the hood almost everything is accessed via pointers. There are exceptions
though, and try/catch. And recently I added exactly what appears to be
your last wish: a MakeDestructor operation which just prepares a function
to be launched when exiting the current scope.

Curiously enough, the script language is itself implemented by quite a
large amount of C++ code, making heavy use of constructors, destructors,
inheritance, exceptions, templates and whatever. I cannot imagine of
doing it in some other language, the full C++ is just a *bare minimum*
for implementing this kind of project.

Paavo


==============================================================================
TOPIC: User defined class meta data (type traits?)
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/f1c011020110c357?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Oct 30 2008 1:55 am
From: anon


greek_bill wrote:
> Hi,
>
> I'm trying to develop a system where I can register some data/
> information about a class. For example
>
> // ClassInfo.h
> template <class T>
> struct ClassInfo
> {
> static const std::string tagName;
> static const int version;
> static const bool isConfigurable;
> };
>
> // FooBar.h
> class FooBar {...};
>
> // FooBar.cpp
> template<> const std::string ClassInfo<FooBar>::tagName = "FooBar";
> template<> const int ClassInfo<FooBar>::version = 1;
> template<> const bool ClassInfo<FooBar>::isConfigurable = false;
>
> // main.cpp
> ...
> #include "FooBar.h"
> if (ClassInfo<FooBar>::isConfigurable)
> {...}
>
> This does what I originally wanted, which is to allow me to associate
> meta-data with some arbitrary class, and have that accessible
> throughout the code.
>

[...]

Does the next example demonstrates what you want?

#include <string>
#include <iostream>

struct A1
{
};
struct A2
{
};

template < class T >
struct At
{
};

template<>
struct At< A1 >
{
static std::string Get()
{
return "A1";
}
};
template<>
struct At< A2 >
{
static std::string Get()
{
return "A2";
}
};
int main()
{
std::cout << At< A1 >::Get() << std::endl;
}


==============================================================================
TOPIC: Why I can't get the correct result
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/77454825337d9113?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Oct 30 2008 1:55 am
From: 348892813@qq.com


I am a student learning C language, I know many of you are good at it.
I need your help.Thank you.
I want to type in a to choose addition, butI can't get the result.
#include <stdio.h>
int main()
{
char character;
float fnum,snum;
printf("Please type in a number:\n");
scanf("%f%f",&fnum,&snum);
printf("Please type in another number:\n");
scanf("%f",&snum);
printf("Enter a select character: ");
printf("\n a for addition");
printf("\n b for multiplication");
printf("\n c for division");
scanf("%c",&character);

switch (character)
{
case 'a':
printf("The sum of the number entered is %6.3f\n",fnum+snum);
break;
case 'b':
printf("The product of the numbers entered is %6.3f\n",fnum*snum);
break;
case 'c':
if(snum != 0.0)
printf("The first number divided by the second is %6.3f\n",fnum/
snum);
else
printf("Division by zero is not allowed\n");
break;
}

return 0;

}

== 2 of 3 ==
Date: Thurs, Oct 30 2008 1:55 am
From: 348892813@qq.com


I am a student learning C language, I know many of you are good at it.
I need your help.Thank you.
I want to type in a to choose addition, butI can't get the result.
#include <stdio.h>
int main()
{
char character;
float fnum,snum;
printf("Please type in a number:\n");
scanf("%f%f",&fnum,&snum);
printf("Please type in another number:\n");
scanf("%f",&snum);
printf("Enter a select character: ");
printf("\n a for addition");
printf("\n b for multiplication");
printf("\n c for division");
scanf("%c",&character);

switch (character)
{
case 'a':
printf("The sum of the number entered is %6.3f\n",fnum+snum);
break;
case 'b':
printf("The product of the numbers entered is %6.3f\n",fnum*snum);
break;
case 'c':
if(snum != 0.0)
printf("The first number divided by the second is %6.3f\n",fnum/
snum);
else
printf("Division by zero is not allowed\n");
break;
}

return 0;

}

== 3 of 3 ==
Date: Thurs, Oct 30 2008 3:28 am
From: Zeppe


348892813@qq.com wrote:
> I am a student learning C language, I know many of you are good at it.
> I need your help.Thank you.
> I want to type in a to choose addition, butI can't get the result.
> #include <stdio.h>
> int main()
> {
> char character;
> float fnum,snum;
> printf("Please type in a number:\n");
> scanf("%f%f",&fnum,&snum);
> printf("Please type in another number:\n");
> scanf("%f",&snum);
> printf("Enter a select character: ");
> printf("\n a for addition");
> printf("\n b for multiplication");
> printf("\n c for division");
> scanf("%c",&character);

are you sure you are reading the values correctly? You won't get the
correct result if you don't retrieve the correct values. Try to print
them out to check them.

Best wishes,

Zeppe


==============================================================================
TOPIC: const correctness - should C++ prefer const member over non-const?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/35cc955f55ea7387?hl=en
==============================================================================

== 1 of 6 ==
Date: Thurs, Oct 30 2008 2:21 am
From: fungus


On Oct 30, 6:31 am, blargg....@gishpuppy.com (blargg) wrote:
>
> I'm interested in why you think it should call the const version. If it
> did, when would it ever call the non-const version?

Ok, maybe I oversimplified it. Supposed operator[]
returns a reference to the int:

int& operator[](int n) {
return data[n];
}
int& operator[](int n) const {
return data[n];
}

If the expression is on the RHS of an assignment, should
the const version be called?


--
<\___/>
/ O O \
\_____/ FTB.

http://www.topaz3d.com/ - New 3D editor!

== 2 of 6 ==
Date: Thurs, Oct 30 2008 2:26 am
From: fungus


On Oct 30, 10:21 am, fungus <openglMYSO...@artlum.com> wrote:
>
> Ok, maybe I oversimplified it. Supposed operator[]
> returns a reference to the int:
>

...and just before the pedants arrive, suppose it's
a struct not an int, and I want to access a member
of the stuct.

my_struct& operator[](int n) { return data[n]; }
const my_struct& operator[](int n) const { return data[n]; }

Why does the compiler choose the non-const version
for the RHS of an expression...?


--
<\___/>
/ O O \
\_____/ FTB.

http://www.topaz3d.com/ - New 3D editor!

== 3 of 6 ==
Date: Thurs, Oct 30 2008 2:41 am
From: anon


fungus wrote:
> I define this class:
>
>
> class foo {
> std::vector<int>data;
> public:
>
> int operator[](int n) {
> return data[n];

Changing this line to this:
return data.at(n);
is much safer

> }
> int operator[](int n) const {
> return data[n];
> }
> };
>
>
> Now in my program I do:
>
> foo myFoo;
> int x = myFoo[123];
> ...
>

This should call the non-const operator[]

If you had:
const foo myFoo;
int x = myFoo[123];
then the const version of the operator[] would be used

>
> Should the const version of foo::operator[] be called?
>
> I think it should, but my compiler disagrees with me.
>
> What's the correct behavior? Why...?
>

== 4 of 6 ==
Date: Thurs, Oct 30 2008 2:42 am
From: anon


fungus wrote:
> On Oct 30, 10:21 am, fungus <openglMYSO...@artlum.com> wrote:
>> Ok, maybe I oversimplified it. Supposed operator[]
>> returns a reference to the int:
>>
>
> ...and just before the pedants arrive, suppose it's
> a struct not an int, and I want to access a member
> of the stuct.
>
> my_struct& operator[](int n) { return data[n]; }
> const my_struct& operator[](int n) const { return data[n]; }
>
> Why does the compiler choose the non-const version
> for the RHS of an expression...?

Because your myFoo object is not const

== 5 of 6 ==
Date: Thurs, Oct 30 2008 2:59 am
From: fungus


On Oct 30, 6:41 am, Jerry Coffin <jcof...@taeus.com> wrote:
>
> > Should the const version of foo::operator[] be called?
>
> No.
>
> > I think it should, but my compiler disagrees with me.
>
> The compiler's right.

Bummer. I've got an object which triggers quite
a big internal rebuild when you call the non-const
version and I just noticed it's doing a lot of
rebuilding because of this assumption.


--
<\___/>
/ O O \
\_____/ FTB.

http://www.topaz3d.com/ - New 3D editor!

== 6 of 6 ==
Date: Thurs, Oct 30 2008 3:29 am
From: SG


On 30 Okt., 10:59, fungus <openglMYSO...@artlum.com> wrote:
> Bummer. I've got an object which triggers quite
> a big internal rebuild when you call the non-const
> version and I just noticed it's doing a lot of
> rebuilding because of this assumption.

You can explicitly convert your object to a const version if you don't
want the non-const member function to be called in some cases:

const foo& myConstFoo = myFoo;
int blah = myConstFoo[42];

or something like that. static_cast<foo const&>(myFoo)[42] should also
work as far as I can tell. Though, these kinds of casts are still a
bit of a mystery to me.

Cheers,
SG


==============================================================================
TOPIC: List erase iterator outside range
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/25a39eff0031f895?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Oct 30 2008 2:45 am
From: James Kanze


On Oct 29, 4:02 pm, Lionel B <m...@privacy.net> wrote:
> On Wed, 29 Oct 2008 07:05:24 -0700, Krice wrote:
> > On 29 loka, 15:50, Lionel B <m...@privacy.net> wrote:

> Yup :-) In future I shall read posts first before responding.
> Might I suggest, though, that `o' is a pretty bad choice of
> name for an identifier (though I have been known to use it
> myself, along with `l').

Not as bad as O (capital):-). (I once saw a program which used
only O, l, 0, 1 and _ in symbols. The source code looked like a
binary dump. And it was a candidate for IOCCC, not production
code.)

If it makes you feel better, I misread it like you did the first
time as well.

> Apart from that I don't see a problem in the code you post,
> which suggests a bug in some other part of your code. A
> compileable example demonstrating the problem would certainly
> help.

Except that in his line:
item_list.erase(pos);
pos isn't an iterator into item_list.

It's true that if he had tried to make his example compilable,
he probably would have found the problem immediately, because he
only would have declared one list, and the compiler would have
complained "symbol not defined" for the other.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


==============================================================================
TOPIC: Replace _T() macros
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/8db5322ba522aa5d?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Oct 30 2008 2:51 am
From: James Kanze


On Oct 29, 5:25 pm, John Doe <mos...@anonymous.org> wrote:

> I would like to know if it would be possible to replace _T()
> macros used on windows to delcare an ANSI string or a unicode
> one :

> #ifdef UNICODE
> #define __TEXT(quote) L##quote // r_winnt
> #else
> #define __TEXT(quote) ##quote
>

No comments: