EDIT: Sorry to waste your time. My problem was simple, I just had the variable declared as extern in the main program. I thought something was right with my operator definition. I do see that I have other issues, like the operator= isn't right below. But, the main issue was just the missing variable.
I haven't used operator overloading in literally 20 years. So, I'm rather rusty. But, my goal is to be able to build map, hash map or unsorted map, where I can store and retrieve an internal ID integer from an IPv6 address. Which of those kinds of structures would be most suitable for my purpose, I'm open to recommendations. I figured I'd try a map first, but, if that isn't the best choice, let me know. I'm told that the requirements of my application will require up to about 100,000 IPv6 addresses. Though I'm also told it probably won't be more than 10,000 for at least a year or two. In any case, my goal is, when handed an IPv6 address, I want to quickly locate my internal ID number for that address.
So, basically, my understanding is that to be able to use the map classes, I need to provide an < operator. And, while at it, I might as well provide the remaining comparison operators. At first, I created the operators not as friend functions, with only one seen operator, and I got a compiler error, saying it was looking for an operator for with two operands. I searched the answers here, and found an answer to that question, I made it friend functions. This time, I don't get a compiler error. But, I get a linker error:
LNK2001: unresolved external symbol "class std::map,class std::allocator > > first" (?first@@3V?$map@Vipmapclass@@HU?$less@Vipmapclass@@@std@@V?$allocator@U?$pair@$$CBVipmapclass@@H@std@@@3@@std@@A) c:\Projects\mapdemo\mapdemo\mapdemo.obj mapdemo
I'm using Visual Studio 2010 in x64 mode, but, I also want the code to work with VS 2008 x64. I'm using Here is my code for the class below. Thanks for any help!
#include "targetver.h"
#include <stdio.h>
#include <stddef.h>
#include <tchar.h>
#include <conio.h>
#include <map>
#include <windows.h>
#include <In6addr.h>
#include <InAddr.h>
class ipmapclass{
public:
union{
in6_addr ip6addr;
unsigned _int64 uint64[2];
};
inline friend bool operator==(const ipmapclass& lhs, const ipmapclass& rhs)
{
return ( (lhs.uint64[0] == rhs.uint64[0]) &&
(lhs.uint64[1] == rhs.uint64[1]) );
}
inline friend bool operator< (const ipmapclass& lhs, const ipmapclass& rhs)
{
return ( (lhs.uint64[0] < rhs.uint64[0]) ||
((lhs.uint64[0] == rhs.uint64[0]) && (lhs.uint64[1] < rhs.uint64[1])) );
}
inline ipmapclass operator= (const ipmapclass& rhs)
{
ipmapclass result;
result.uint64[0] = rhs.uint64[0];
result.uint64[1] = rhs.uint64[1];
return (result);
}
inline friend bool operator> (const ipmapclass& lhs, const ipmapclass& rhs){return rhs < lhs;}
inline friend bool operator<=(const ipmapclass& lhs, const ipmapclass& rhs){return !(lhs > rhs);}
inline friend bool operator>=(const ipmapclass& lhs, const ipmapclass& rhs){return !(lhs < rhs);}
};
extern std::map<ipmapclass, int> first;