Trying to access a struct member in class Hand with the following error: error: C2228: left of ‘.colorBet’ must have class/struct/union
hand.h
#ifndef HAND_H
#define HAND_H
#include"deck.h"
#include <QVector>
#include <QString>
struct street
{
QString colorBet;
int colorBetSize;
int payout;
};
class Hand
{
QVector<card> cardVector;
public:
Hand(QVector<card> vCards);
bool isFlush();
bool isAllRed();
bool isAllBlack();
street street1;
street street2;
street street3;
};
#endif // HAND_H
mainwindow.cpp (error near the bottom)
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "hand.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::build_radios(){
street1BetBlack = new QRadioButton("Black");
connect(street1BetBlack, SIGNAL(clicked()),
this, SLOT(street1BetBlackClicked()));
street2BetBlack = new QRadioButton("Black");
connect(street2BetBlack, SIGNAL(clicked()),
this, SLOT(street2BetBlackClicked()));
street3BetBlack = new QRadioButton("Black");
connect(street3BetBlack, SIGNAL(clicked()),
this, SLOT(street3BetBlackClicked()));
street1BetRed = new QRadioButton("Red");
connect(street1BetRed, SIGNAL(clicked()),
this, SLOT(street1BetRedClicked()));
street2BetRed = new QRadioButton("Red");
connect(street2BetRed, SIGNAL(clicked()),
this, SLOT(street2BetRedClicked()));
street3BetRed = new QRadioButton("Red");
connect(street3BetRed, SIGNAL(clicked()),
this, SLOT(street3BetRedClicked()));
st1bg = new QButtonGroup;
st2bg = new QButtonGroup;
st3bg = new QButtonGroup;
// button groups
st1bg->addButton(street1BetBlack);
st1bg->addButton(street1BetRed);
st1bg->setExclusive(true);
st2bg->addButton(street2BetBlack);
st2bg->addButton(street2BetRed);
st2bg->setExclusive(true);
st3bg->addButton(street3BetBlack);
st3bg->addButton(street3BetRed);
st3bg->setExclusive(true);
}
void MainWindow::street1BetRedClicked()
{
Hand::street1.colorBet="Red"; //error on every line similar to this
}
void MainWindow::street2BetRedClicked()
{
Hand::street2.colorBet="Red";
}
void MainWindow::street3BetRedClicked()
{
Hand::street3.colorBet="Red";
}
void MainWindow::street1BetBlackClicked()
{
Hand::street1.colorBet="Black";
}
void MainWindow::street2BetBlackClicked()
{
Hand::street2.colorBet="Black";
}
void MainWindow::street3BetBlackClicked()
{
Hand::street3.colorBet="Black";
}
Hand::street1.colorBet="Red";& the others are illegal becauseHand::street1isn’t astaticclass member (I’m not saying it should, havingstaticmembers should be a logic decision, not something you do to make the code compile).What
Handobject are you attempting to modify in, say,street1BetRedClicked? Do you have anyHandobjects? Do you need anyHandobjects? Do you create them in that method? Outside?I pointed out the error, but it seems to me that the important issue here isn’t the fact that the code doesn’t compile, but that:
You don’t seem to have a firm grasp on C++, perhaps you should start with something simpler.
You don’t have a clear logic set up.