成员类声明问题
我对班级成员和我的声明有疑问。第一段代码是我的“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”不属于成员类别。
#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;
}
I have having issues with class members and my declaration. The first segment of code is my header file for "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 */
The below segment of code is the coding in question the asterix lines are where I am having errors in the compile for "tiles" not being declared and "tiles" not being in member class.
#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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在
TileMapper
中将tiles
声明为私有?如果是这种情况,您应该将其声明为 public 或 protected,以便子类可以访问它。Did you declare
tiles
as private inTileMapper
? If that's the case you should declare it public or protected so the child class can access it.