typedef operator()没有为std :: map排序编译

问题描述 投票:0回答:1

我正在尝试编译一个类,其中std :: map首先是一个类指针。当我创建类时,我向前声明了类,但如果我尝试取消引用指针,则说操作符<尚未退出。由于我在类函数参数中使用typedef,因此我无法将其移动到包含的底部,因为函数说FdTEcApplDataMap尚未声明。如何编译这个类?不知何故,我需要让FoEcApplDataPComp看到运算符<include the class。

#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
c++ typedef stdmap
1个回答
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和另一部分因为普通指针应该被价值接受。

© www.soinside.com 2019 - 2024. All rights reserved.