0
我有類成員和我的聲明問題。第一個代碼段是「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 */
的代碼如下段是有問題的編碼的星號行是我有對「磚」的編譯錯誤沒有被聲明並且「tiles」不在成員類中。
#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;
}
'tiles'成員聲明在哪裏?我們應該猜測它在'TileMapper'中嗎? –
tiles變量未在KDTileMapper中聲明。它是否在TileMapper中聲明?如果是這樣,問題可能在TileMapper中,你可以發佈該類的代碼嗎? – fbafelipe
你的編譯器似乎表明在範圍內沒有任何名爲'tiles'的聲明。我也沒有看到類似的東西。這個聲明應該是在哪裏?你能證明嗎? –