成员类声明问题

发布于 2024-11-26 17:02:15 字数 2271 浏览 2 评论 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 */

下面的代码段是有问题的编码 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清眉祭 2024-12-03 17:02:15

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

Did you declare tiles as private in TileMapper ? If that's the case you should declare it public or protected so the child class can access it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文