我有錯誤C2227麻煩,這裏是我的代碼錯誤C2227:左「 - >寬度」必須指向類/結構/聯合/泛型類型,光線投射渲染
我不知道如何有存取權限從音量 - > voxel->寬度MyWindow,我必須得到一個寬度的音量數據。
我編輯了一篇文章。我在Volume類型中創建了一個指針,但它不起作用。
MyWindow.cpp
#include "MainWindow.h"
#include <QFileDialog>
#include <QPainter>
#include "Volume.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), m_Volume(0), m_VectorField(0)
{
m_Ui = new Ui_MainWindow();
m_Ui->setupUi(this);
connect(m_Ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFileAction()));
connect(m_Ui->actionClose, SIGNAL(triggered()), this, SLOT(closeAction()));
float width = m_Ui->label->width();
float height = m_Ui->label->height();
(float i = 0; i < m_Volume->voxel->width; i++) // HERE IS ERROR
{
m_Ui->label->width();
}
QPixmap map(width, height);
map.fill(QColor(255, 0, 0, 0));
}
volume.h
// Voxel
//-------------------------------------------------------------------------------------------------
class Voxel
{
public:
Voxel();
Voxel(const Voxel &other);
Voxel(const float value);
~Voxel();
// VOXEL VALUE
void setValue(const float value);
const float getValue() const;
// OPERATORS
const bool operator==(const Voxel &other) const;
const bool operator!=(const Voxel &other) const;
const bool operator>(const Voxel &other) const;
const bool operator>=(const Voxel &other) const;
const bool operator<(const Voxel &other) const;
const bool operator<=(const Voxel &other) const;
const Voxel operator+(const Voxel &other) const;
const Voxel operator-(const Voxel &other) const;
const Voxel operator*(const float &value) const;
const Voxel operator/(const float &value) const;
const Voxel& operator+=(const Voxel &other);
const Voxel& operator-=(const Voxel &other);
const Voxel& operator*=(const float &value);
const Voxel& operator/=(const float &value);
private:
float m_Value;
};
//-------------------------------------------------------------------------------------------------
// Volume
//-------------------------------------------------------------------------------------------------
class Volume
{
public:
Volume();
~Volume();
// VOLUME DATA
const Voxel& voxel(const int i) const;
const Voxel& voxel(const int x, const int y, const int z) const;
const Voxel* voxels() const;
const int width() const;
const int height() const;
const int depth() const;
const int size() const;
bool loadFromFile(QString filename, QProgressBar* progressBar);
private:
std::vector<Voxel> m_Voxels;
int m_Width;
int m_Height;
int m_Depth;
int m_Size;
};
請將[你的問題]寫成[mcve]。這隻需要聲明m_Volume,賦值給它,並嘗試訪問寬度。我們還需要所有相關類型的完整定義。 –
我有,編輯過一個帖子 –
Voxel沒有寬度作爲成員。卷的確如此。所以不應該是'm_Volume-> width()'而不是'm_Volume-> voxel-> width'? – drescherjm