成员类声明问题

时间:2011-07-27 23:49:16

标签: c++ class declaration member

我遇到了班级成员和我的声明问题。第一段代码是我的“kdtilemapper.h”头文件

#ifndef _KDTILEMAPPER_H
#define _KDTILEMAPPER_H

#include "tilemapper.h"
#include "kdtree.h"

class KDTileMapper : public TileMapper{
public:
    KDTileMapper( const SourceImage & si,const vector<TileImage> & tiles);
    ~KDTileMapper();
    KDTileMapper(const KDTileMapper & rhs);
    KDTileMapper const & operator=(KDTileMapper const & rhs);
    int map_tiles(MosaicCanvas & mosaicOut) const;
private:
};
#endif /* _KDTILEMAPPER_H */

下面的代码段是有问题的编码, asterix 行是我在编译中遇到错误的地方,因为“tiles”未被声明,而“tiles”不在成员类中。< / p>

#include "kdtilemapper.h"
#include "kdtree.h"

KDTileMapper::KDTileMapper(const SourceImage & si, const vector<TileImage> & tiles):TileMapper(si,tiles)
{
    //TileMapper(si,tiles);
    //tileMapKDT=NULL;
}
KDTileMapper::~KDTileMapper(){


}
KDTileMapper::KDTileMapper(const KDTileMapper & rhs):TileMapper(rhs)
{
    source = rhs.source;
    **tiles = rhs.tiles;**  //tiles not declared and not member of const class KDTileMapper
}
KDTileMapper const & KDTileMapper::operator=(KDTileMapper const & rhs)
{
    source = rhs.source;
    **tiles= rhs.tiles;** //tiles not declared and not member of const class KDTileMapper
    return *this;
}
int KDTileMapper::map_tiles(MosaicCanvas & mosaicOut) const{
    int check1;
    TileImage tempTile1;
    TileImage tempTile2;
    int rows=source.get_rows();
    int columns=source.get_columns();
    **if(tiles.empty() || rows<0 || colums<0)** //tiles not declared, neither colums
    return -1;
    **KDTree<TileImage>* tileMapKDT= new KDTree<TileImage>(tiles[0].get_num_levels());**
    //tiles above is not declared
    for(int j=0;j< (int)tiles.size();j++)
    {
        if(!tiles[j].is_valid())
        return -1;
    }
    check1= tileMapKDT->create_tree(tiles);
    if(check1<0)
    return -1;

    mosaicOut=MosaicCanvas(rows,columns);
    for(int i=0;i<rows;i++)
    {
        for(int j=0;j<columns;j++)
        {
        tempTile1=TileImage(source.get_region_color(i,j));
        tempTile2=tileMapKDT->find_nearest_neighbor(tempTile1);
        mosaicOut.set_tile(i,j,tempTile2);
    }
}
return 0;
}

1 个答案:

答案 0 :(得分:0)

您是否在tiles中将TileMapper声明为私有?如果是这种情况,您应该将其声明为public或protected,以便子类可以访问它。