M
Mike Copeland
I am trying to convert an array-based application to a vector-based
implementation, mostly because I need to expand the data being processed
beyond a fixed array I've declared (CTSMAX), but also to make use of
higher level structures and techniques.
I've declared a vector (cszVect) that contains sub-structure (CSTYPE)
which contains the data key to be sorted.
When I coded a sort call (sort(cszVect.begin(), cszVect.end())
I
get many compiler errors informing me I don't have a comparison operator
for the data key (csKey) that's in one of the substructures.
I've tried placing the comparison operator code in both the structures,
one at a time - the compiler doesn't like either.
Can I sort a structure on data that exists within an inner
structure? If so, how? TIA
struct CSTYPE
{
string csKey; // City/State "Key"
string csString // City & State data
// bool operator <(const CSTYPE &rhs) const
// {
// return csKey < rhs.csKey;
// }
} ;
struct ZIPTYPE
{ // ZIP codes for City
long loZIP, hiZIP; // ZIP Code ranges
int zipCount; // Usage Count of City/State
} ;
struct CSZTYPE
{ // combined City, State, ZIP info for Entry
CSTYPE csData;
// bool operator <(const CSTYPE &rhs) const
// {
// return csData.csKey < rhs.csKey;
// }
ZIPTYPE zipData;
} ;
typedef vector<CSZTYPE> CSZINFO;
CSZINFO cszVect; // City, State, ZIP data storage
implementation, mostly because I need to expand the data being processed
beyond a fixed array I've declared (CTSMAX), but also to make use of
higher level structures and techniques.
I've declared a vector (cszVect) that contains sub-structure (CSTYPE)
which contains the data key to be sorted.
When I coded a sort call (sort(cszVect.begin(), cszVect.end())
get many compiler errors informing me I don't have a comparison operator
for the data key (csKey) that's in one of the substructures.
I've tried placing the comparison operator code in both the structures,
one at a time - the compiler doesn't like either.
Can I sort a structure on data that exists within an inner
structure? If so, how? TIA
struct CSTYPE
{
string csKey; // City/State "Key"
string csString // City & State data
// bool operator <(const CSTYPE &rhs) const
// {
// return csKey < rhs.csKey;
// }
} ;
struct ZIPTYPE
{ // ZIP codes for City
long loZIP, hiZIP; // ZIP Code ranges
int zipCount; // Usage Count of City/State
} ;
struct CSZTYPE
{ // combined City, State, ZIP info for Entry
CSTYPE csData;
// bool operator <(const CSTYPE &rhs) const
// {
// return csData.csKey < rhs.csKey;
// }
ZIPTYPE zipData;
} ;
typedef vector<CSZTYPE> CSZINFO;
CSZINFO cszVect; // City, State, ZIP data storage