我正在尝试编译一个类,其中std :: map首先是类指针。当我创建类时,我会向前声明该类,但是如果我尝试取消对指针的引用,它会表示operator <尚未退出。由于我在类函数参数中使用了typedef,因此无法将其移至包含的底部,因为那时函数尚未声明FdTEcApplDataMap。我该如何编译该类?我需要某种方式获取FoEcApplDataPComp才能看到操作符<包括该类。
#ifndef _FoEcApplData_h_
#define _FoEcApplData_h_
#include <boost/serialization/string.hpp>
class RWDlistCollectables ;
#include "EcTypes.h"
#include "EcBcArch.h"
const RWClassID FoCEcApplData = 90;
// forward declare so we can declare FdTEcApplDataMap typedef
class FoEcApplData;
/*
Custom KeyEqual for FoEcApplData class on FdTEcApplDataMap.
Needed since we are using pointers.
Note: Each FoEcApplData is unique so you can't be equal.
Returns - true less then, false equal and greater
lhs - pointer to the item you are looking for
rhs - pointer to an item on the list
*/
struct FoEcApplDataPComp
{
bool operator()(FoEcApplData *const& lhs, FoEcApplData *const& rhs) const
{
return (*lhs < *rhs);
}
};
/*
NOTE:
You can NOT use the map find() call because the "operator<" is testing the array
length vs. what's inside the array. Instead you must use FoEcApplData.find().
*/
typedef std::map<FoEcApplData *, std::string, FoEcApplDataPComp> FdTEcApplDataMap;
// FoEcApplData : public EcRwCollectable
//
// This is the application data for a directive. That is the binary for
// the directive alone without a packet header.
class FoEcApplData : public EcRwCollectable {
EcMBcArchSplitDeclareClass(FoEcApplData,EcRwCollectable)
public:
// FoEcApplData
//
// Default Constructor.
FoEcApplData() ;
// FoEcApplData
//
// Copy Constructor.
FoEcApplData( const FoEcApplData& object ) ;
// FoEcApplData
//
// Destructor.
virtual ~FoEcApplData() ;
// operator=
//
// Set this object equal to input object.
FoEcApplData& operator=( const FoEcApplData& object) ;
// operator==
//
// Test to see if this is equal to input object.
bool operator==( const FoEcApplData& object) const ;
// operator<
//
// Test to see if input object is less than input object.
bool operator<( const FoEcApplData& object) const ;
// operator>
//
// Test to see if input object is greater than input object.
bool operator>( const FoEcApplData& object) const ;
// operator+=
//
// Add the input applicationsd data to my own appending
// to end of binary array. Returns a reference to self.
FoEcApplData& operator+=( const FoEcApplData& object ) ;
/*
Print out the class in a human readable format
Returns - output stream
os - output stream
orig - Reference to class so we can print it out
*/
friend std::ostream& operator<<(std::ostream& os, const FoEcApplData& orig);
// find
//
// The std::map find call can't work because the operator< is not testing the array contented.
// This will loop through the map key and compare each once for a match.
//
// returns - the iterator for the search
//
// applDataMap - the map list reference
// object - The object you are trying to find in the map list
FdTEcApplDataMap::const_iterator find(const FdTEcApplDataMap& applDataMap, const FoEcApplData * pObject);
// Data
//
// Get the binary data.
inline const EcTOctet* Data() const;
// NumOfBytes
//
// Size of the binary in bytes. 0 indicates no binary data.
inline EcTInt NumOfBytes() const;
// Data
//
// Set the binary. I take possesion of the data.
inline EcTVoid Data( EcTOctet* data , const EcTInt& dataSize ) ;
// binaryStoreSize
//
// Computes the size of the class when stored using saveGuts.
virtual RWspace binaryStoreSize() const ;
// hash
//
// Returns a value suitable for a hash table.
virtual EcTUInt hash() const ;
// restoreGuts
//
// Recreates a class from file. (persistance)
//
// RWFileErr - thrown on file error.
virtual EcTVoid restoreGuts( RWFile& file) ;
// restoreGuts
//
// Recreates a class from stream. (persistance)
virtual EcTVoid restoreGuts( RWvistream& inStream ) ;
// saveGuts
//
// Saves a class to a file. (persistance)
//
// RWFileErr - thrown on file error.
virtual EcTVoid saveGuts( RWFile& file) const ;
// saveGuts
//
// Saves a class to a stream. (persistance)
virtual EcTVoid saveGuts( RWvostream& outStream ) const ;
// getDataMemberDifferences
//
// Compare the all of the data members that are streamed out.
// Returns true if it found descrepancies. It also fills a collection
// with strings containing all of the differences and possible
// causes
virtual EcTBoolean
getDataMemberDifferences(
const FoEcApplData* compareApplData,
RWDlistCollectables& listOfDescrepancies) const;
private:
// The actual data (binary). This is a pointer to an array of
// EcTOctet that is myNumOfBytes long.
EcTOctet* myData;
// The length of the binary in bytes.
EcTInt myNumOfBytes;
};
// Include inline functions...
#ifndef OUTLINE
#include "FoEcApplData.iC"
#endif
BOOST_CLASS_EXPORT_KEY(FoEcApplData)
#endif
答案 0 :(得分:2)
在FoEcApplDataPComp::operator()
的定义之后提供FoEcApplData
的定义:
struct FoEcApplDataPComp {
inline bool operator()(FoEcApplData const* lhs, FoEcApplData const* rhs) const;
};
class FoEcApplData : public EcRwCollectable { ... };
bool FoEcApplDataPComp::operator()(FoEcApplData const* lhs, FoEcApplData const* rhs) const {
return *lhs < *rhs;
}
也将FoEcApplData *const&
更改为FoEcApplData const*
。部分原因是FoEcApplData::operator() const
,另一部分原因是纯指针应被值接受。