Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Map to stor...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 45803 of 47032
Post > Topic >>

Re: Map to store 3 items

by Juha Nieminen <nospam@[EMAIL PROTECTED] > May 8, 2008 at 10:44 AM

Jerry Coffin wrote:
> class key { 
> 	string name;
> 	string prefix;
> public:
> 	key(string n, string p) : name(n), prefix(p) {}
> 	key(key const &other) : name(other.name), prefix(other.prefix) {}
> 	key &operator=(key const &other) {
> 		name = other.name;
> 		prefix = other.prefix;
> 		return *this;
> 	}

  What exactly do you need that copy constructor and assignment operator
for? They are doing exactly what the default ones would do. They are
useless.

  How about simply:

struct Key
{
    std::string name, prefix;

    Key(std::string& n = "", std::string p = ""): name(n), prefix(p) {}

    bool operator<(const Key& rhs)
    {
        return name == rhs.name ? prefix < rhs.prefix : name < rhs.name;
    }
}
 




 8 Posts in Topic:
Map to store 3 items
Brad <brad@[EMAIL PROT  2008-05-07 21:26:03 
Re: Map to store 3 items
"Alf P. Steinbach&qu  2008-05-08 04:02:24 
Re: Map to store 3 items
Jerry Coffin <jcoffin@  2008-05-07 22:36:57 
Re: Map to store 3 items
Juha Nieminen <nospam@  2008-05-08 10:44:14 
Re: Map to store 3 items
Jerry Coffin <jcoffin@  2008-05-08 19:07:21 
Re: Map to store 3 items
Paavo Helde <nobody@[E  2008-05-08 00:03:55 
Re: Map to store 3 items
James Kanze <james.kan  2008-05-09 05:37:52 
Re: Map to store 3 items
=?utf-8?Q?David_C=C3=B4me  2008-05-08 10:34:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:15:22 CDT 2008.