Prev: Why is CArchive class not derived from Cobject class in MFC
Next: What happens when Win+E is pressed?
From: Vladimir Grigoriev on 22 Jan 2010 07:29 "Ulrich Eckhardt" <eckhardt(a)satorlaser.com> wrote in message news:v63o27-ijd.ln1(a)satorlaser.homedns.org... > Vladimir Grigoriev wrote: >> For example you can define a Point class derived from std::pair. And your >> Point class may have arithmetic operators. You may to add a std::pair >> object to a Point object but your may not add a Point object to a >> std:pair >> object. > > Why not? If a+b computes then b+a should, too. > Well, when try to build two template classes one derived from another such a way that the base class will not get a new feature of the derived class. For example template <typename T> class A { .... template <typename U> A( const A<U> & ); .... }; template <typename T> class B: public A<T> { .... template <typename U> B( const B<U> & ); .... }; and class A for example has no a sum operation while class B has. So the following should be valid A a; B b; b + b; b + a; a + b; however a + a is not valid Vladimir Grigoriev
From: Vladimir Grigoriev on 22 Jan 2010 07:43 Sorry I have not understood all you have said due to may bad English. Yes, the class Person has a field for example of size_t which denotes personal identification. For example this member may play also a role of a key in a data base. There is no sense to compare two persons because it is obvious that they are different. However there is a sense to compare an object of the class Person with a personal identification for example in search operations or in operations with sets. However there is no a constructor for Person which takes only one argument - personal ID. Of course it is artificial example. Vladimir Grigoriev .. "Duane Hebert" <spoo(a)flarn.com> wrote in message news:eQL3qItmKHA.4936(a)TK2MSFTNGP04.phx.gbl... > > "sasha" <abc(a)fox.net> wrote in message > news:O49e7$smKHA.6096(a)TK2MSFTNGP02.phx.gbl... >> Duane Hebert wrote: >>> >> >>> >>> What has the ctor for your class to do with the == operator for your >>> class? >>> Maybe I'm missing someting... >>> >>> >> >> It may need to be constructed before compared - like when OP said during >> iteration of an array of IDs. > > But if I have a ctor taking int, string and another taking string,int how > does it relate to the > == operator? This compares instances of an object that has already been > constructed. > I can have 27 ctors for a class and only one == operator.
From: Duane Hebert on 22 Jan 2010 08:43 "sasha" <abc(a)fox.net> wrote in message news:OOVV2qvmKHA.760(a)TK2MSFTNGP02.phx.gbl... > Duane Hebert wrote: > >> But if I have a ctor taking int, string and another taking string,int >> how does it relate to the >> == operator? This compares instances of an object that has already been >> constructed. >> I can have 27 ctors for a class and only one == operator. > > The STL algorithms may not use all of available constructors. I guess I don't understand what you mean by the STL algorithms using constructors. Can you give me an example of one that has to construct something?
From: Ulrich Eckhardt on 22 Jan 2010 08:58 Vladimir Grigoriev wrote: > "Ulrich Eckhardt" <eckhardt(a)satorlaser.com> wrote in message > news:v63o27-ijd.ln1(a)satorlaser.homedns.org... >> Vladimir Grigoriev wrote: >>> For example you can define a Point class derived from std::pair. And >>> your Point class may have arithmetic operators. You may to add a >>> std::pair object to a Point object but your may not add a Point object >>> to a std:pair >>> object. >> >> Why not? If a+b computes then b+a should, too. >> > > Well, when try to build two template classes one derived from another such > a way that the base class will not get a new feature of the derived class. > > For example > > template <typename T> > class A > { > ... > template <typename U> > A( const A<U> & ); > ... > }; > template <typename T> > class B: public A<T> > { > ... > template <typename U> > B( const B<U> & ); > ... > }; > > and class A for example has no a sum operation while class B has. > So the following should be valid > > A a; > B b; > > b + b; > b + a; > a + b; So, a+b computes just as well as b+a, just as I said it should. > however > a + a is not valid I never claimed it should. Uli -- C++ FAQ: http://parashift.com/c++-faq-lite Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: Vladimir Grigoriev on 22 Jan 2010 09:26
"Ulrich Eckhardt" <eckhardt(a)satorlaser.com> wrote in message news:4hno27-ple.ln1(a)satorlaser.homedns.org... > Vladimir Grigoriev wrote: >> "Ulrich Eckhardt" <eckhardt(a)satorlaser.com> wrote in message >> news:v63o27-ijd.ln1(a)satorlaser.homedns.org... >>> Vladimir Grigoriev wrote: >>>> For example you can define a Point class derived from std::pair. And >>>> your Point class may have arithmetic operators. You may to add a >>>> std::pair object to a Point object but your may not add a Point object >>>> to a std:pair >>>> object. >>> >>> Why not? If a+b computes then b+a should, too. >>> >> >> Well, when try to build two template classes one derived from another >> such >> a way that the base class will not get a new feature of the derived >> class. >> >> For example >> >> template <typename T> >> class A >> { >> ... >> template <typename U> >> A( const A<U> & ); >> ... >> }; >> template <typename T> >> class B: public A<T> >> { >> ... >> template <typename U> >> B( const B<U> & ); >> ... >> }; >> >> and class A for example has no a sum operation while class B has. >> So the following should be valid >> >> A a; >> B b; >> >> b + b; >> b + a; >> a + b; > > So, a+b computes just as well as b+a, just as I said it should. > >> however >> a + a is not valid > > I never claimed it should. > However try to provide that a + a will not compute when a + b, b + a, and b + b will compute for two classes when one is derived from another.. Vladimir Grigoriev |