How to get the date from a calendar widget in gtkmm3? - c++

So I don't understand how to get this thing working.
I already read the Class reference but the only two references to get_date() return void. How can I get the date from a calendar widget?.
I now that I'm calling the method wrong and this cause the errors.
This is my Notebook.hpp
#pragma once
#include <gtkmm.h>
class NotebookMain : public Gtk::Window{
public:
NotebookMain();
virtual ~NotebookMain();
protected:
// Signal handlers
void on_notebook_switch_page(Gtk::Widget *page, guint page_num);
void on_button_add_appointment();
// Member widgets
Gtk::Notebook notebookMain;
Gtk::Label label1, labelTest;
Gtk::Box boxDatebook, boxCalendar
Gtk::Calendar calendar;
Gtk::Button buttonAddAppointment;
};
This is my Notebook.cpp
#include <iostream>
#include "../include/NotebookMain.hpp"
NotebookMain::NotebookMain() : label1("Hello from inside Tab 2!"),
labelTest("Hello from inside Appointments"){
this->set_title("Test");
this->set_default_size(640, 480);
// Create Calendar Box
boxCalendar.set_orientation(Gtk::ORIENTATION_VERTICAL);
boxCalendar.pack_start(calendar);
buttonAddAppointment.set_label("Add Appointment");
boxCalendar.pack_start(buttonAddAppointment);
// Create Appointments Box
boxAppointments.set_orientation(Gtk::ORIENTATION_VERTICAL);
boxAppointments.pack_start(labelTest);
// Create Datebok Box
boxDatebook.set_orientation(Gtk::ORIENTATION_HORIZONTAL);
boxDatebook.pack_start(boxCalendar);
boxDatebook.pack_end(boxAppointments);
// Set Notebook
notebookMain.set_border_width(0);
// Add Notebook tabs
notebookMain.append_page(boxDatebook, "Datebook");
notebookMain.append_page(label1, "Tab 2");
// Switch tabs
notebookMain.signal_switch_page().connect(sigc::mem_fun(*this, &NotebookMain::on_notebook_switch_page));
// Get Date
buttonAddAppointment.signal_clicked().connect(sigc::mem_fun(*this, &NotebookMain::on_button_add_appointment));
// Add Main Window (Notebook)
this->add(notebookMain);
this->show_all_children();
}
NotebookMain::~NotebookMain(){}
void NotebookMain::on_notebook_switch_page(Gtk::Widget * /* page */, guint page_num){
std::cout << "Switched to tab with index : " << page_num << std::endl;
}
void NotebookMain::on_button_add_appointment(){
std::cout << "Button clicked\n";
std::cout << calendar.get_date() << "\n";
}
And the errors
src/NotebookMain.cpp: In member function ‘void NotebookMain::on_button_add_appointment()’:
src/NotebookMain.cpp:51:23: error: no matching function for call to ‘Gtk::Calendar::get_date()’
51 | calendar.get_date();
| ^
In file included from /usr/include/gtkmm-3.0/gtkmm.h:196,
from src/../include/NotebookMain.hpp:3,
from src/NotebookMain.cpp:3:
/usr/include/gtkmm-3.0/gtkmm/calendar.h:299:8: note: candidate: ‘void Gtk::Calendar::get_date(guint&, guint&, guint&) const’
299 | void get_date(guint& year, guint& month, guint& day) const;
| ^~~~~~~~
/usr/include/gtkmm-3.0/gtkmm/calendar.h:299:8: note: candidate expects 3 arguments, 0 provided
/usr/include/gtkmm-3.0/gtkmm/calendar.h:305:8: note: candidate: ‘void Gtk::Calendar::get_date(Glib::Date&) const’
305 | void get_date(Glib::Date& date) const;
| ^~~~~~~~
/usr/include/gtkmm-3.0/gtkmm/calendar.h:305:8: note: candidate expects 1 argument, 0 provided
make: *** [makefile:9: NotebookMain.o] Error 1

This solved the problem. I need to pass the arguments, and then those variables will stored the value from the calendar.
unsigned int year, month, day;
calendar.get_date(year, month, day);
Pro tip: Read the documentation right!.

Related

exitprompt.cpp:268:22: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]

I'm trying to modify some C++ code but I and getting the following errors during build:
make[2]: Leaving directory '/home/runner/work/mythtv/mythtv/mythtv/programs/mythlcdserver'
cd mythshutdown/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake -o Makefile /home/runner/work/mythtv/mythtv/mythtv/programs/mythshutdown/mythshutdown.pro QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake ) && make -f Makefile
exitprompt.cpp: In member function ‘void ExitPrompter::Confirm(MythPower::Feature) const’:
Makefile:4570: recipe for target 'obj/exitprompt.o' failed
exitprompt.cpp:268:22: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
make[2]: Leaving directory '/home/runner/work/mythtv/mythtv/mythtv/programs/mythfrontend'
DoHalt(true);
Makefile:89: recipe for target 'sub-mythfrontend-make_first' failed
^
exitprompt.cpp:39:6: note: in call to ‘void ExitPrompter::DoHalt(bool)’
void ExitPrompter::DoHalt(const bool Confirmed)
^~~~~~~~~~~~
exitprompt.cpp:270:24: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoReboot(true);
^
exitprompt.cpp:70:6: note: in call to ‘void ExitPrompter::DoReboot(bool)’
void ExitPrompter::DoReboot(const bool Confirmed)
^~~~~~~~~~~~
exitprompt.cpp:272:25: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoSuspend(true);
^
exitprompt.cpp:100:6: note: in call to ‘void ExitPrompter::DoSuspend(bool)’
void ExitPrompter::DoSuspend(const bool Confirmed)
^~~~~~~~~~~~
make[2]: *** [obj/exitprompt.o] Error 1
make[1]: *** [sub-mythfrontend-make_first] Error 2
The code is as follows:
// Qt
#include <QCoreApplication>
// MythTV
#include "config.h"
#include "exitprompt.h"
#include "mythcontext.h"
#include "mythdialogbox.h"
#include "mythmainwindow.h"
#include "mythscreenstack.h"
#include "mythsystemlegacy.h"
#include "mythlogging.h"
#include "exitcodes.h"
ExitPrompter::ExitPrompter()
: m_power(MythPower::AcquireRelease(this, true)),
m_haltCommand(gCoreContext->GetSetting("HaltCommand", "")),
m_rebootCommand(gCoreContext->GetSetting("RebootCommand", "")),
m_suspendCommand(gCoreContext->GetSetting("SuspendCommand", ""))
{
}
ExitPrompter::~ExitPrompter()
{
if (m_power)
MythPower::AcquireRelease(this, false);
}
void ExitPrompter::DoQuit()
{
qApp->exit();
}
void ExitPrompter::ConfirmHalt() const
{
Confirm(MythPower::FeatureShutdown);
}
void ExitPrompter::DoHalt(const bool Confirmed)
{
if (!Confirmed)
return;
// Use user specified command if it exists
if (!m_haltCommand.isEmpty())
{
uint ret = myth_system(m_haltCommand);
if (ret == GENERIC_EXIT_OK)
return;
LOG(VB_GENERAL, LOG_ERR,
"User defined HaltCommand failed, falling back to "
"alternative methods.");
}
// Otherwise use MythPower
if (m_power && m_power->IsFeatureSupported(MythPower::FeatureShutdown))
if (m_power->RequestFeature(MythPower::FeatureShutdown))
return;
// halt of last resort
myth_system("sudo /sbin/halt -p");
}
void ExitPrompter::ConfirmReboot() const
{
Confirm(MythPower::FeatureRestart);
}
void ExitPrompter::DoReboot(const bool Confirmed)
{
if (!Confirmed)
return;
if (!m_rebootCommand.isEmpty())
{
uint ret = myth_system(m_rebootCommand);
if (ret == GENERIC_EXIT_OK)
return;
LOG(VB_GENERAL, LOG_ERR,
"User defined RebootCommand failed, falling back to "
"alternative methods.");
}
// Otherwise use MythPower
if (m_power && m_power->IsFeatureSupported(MythPower::FeatureRestart))
if (m_power->RequestFeature(MythPower::FeatureRestart))
return;
// reboot of last resort
myth_system("sudo /sbin/reboot");
}
void ExitPrompter::ConfirmSuspend(void) const
{
Confirm(MythPower::FeatureSuspend);
}
void ExitPrompter::DoSuspend(const bool Confirmed)
{
if (!Confirmed)
return;
// Use user specified command if it exists
if (!m_suspendCommand.isEmpty())
{
uint ret = myth_system(m_suspendCommand);
if (ret == GENERIC_EXIT_OK)
return;
LOG(VB_GENERAL, LOG_ERR,
"User defined SuspendCommand failed, falling back to "
"alternative methods.");
}
if (m_power && m_power->IsFeatureSupported(MythPower::FeatureSuspend))
m_power->RequestFeature(MythPower::FeatureSuspend);
}
void ExitPrompter::DoStandby()
{
GetMythMainWindow()->IdleTimeout();
}
void ExitPrompter::HandleExit()
{
// HACK IsFrontendOnly() triggers a popup if there is no BE connection.
// We really don't need that right now. This hack prevents it.
gContext->SetDisableEventPopup(true);
// first of all find out, if this is a frontend only host...
bool frontendOnly = gCoreContext->IsFrontendOnly();
// HACK Undo the hack, just in case we _don't_ quit:
gContext->SetDisableEventPopup(false);
// how do you want to quit today?
bool allowExit = false;
bool allowReboot = false;
bool allowShutdown = false;
bool allowStandby = false;
bool allowSuspend = false;
bool haveshutdown = !m_haltCommand.isEmpty();
bool havereboot = !m_rebootCommand.isEmpty();
bool havesuspend = !m_suspendCommand.isEmpty();
#ifdef Q_OS_ANDROID
haveshutdown = false;
havereboot = false;
havesuspend = false;
#endif
if (m_power)
{
havereboot |= m_power->IsFeatureSupported(MythPower::FeatureRestart);
haveshutdown |= m_power->IsFeatureSupported(MythPower::FeatureShutdown);
havesuspend |= m_power->IsFeatureSupported(MythPower::FeatureSuspend);
}
switch (gCoreContext->GetNumSetting("OverrideExitMenu", 0))
{
case 0:
allowExit = true;
if (frontendOnly)
allowShutdown = haveshutdown;
break;
case 1:
allowExit = true;
break;
case 2:
allowExit = true;
allowShutdown = haveshutdown;
break;
case 3:
allowExit = true;
allowReboot = havereboot;
allowShutdown = haveshutdown;
break;
case 4:
allowShutdown = haveshutdown;
break;
case 5:
allowReboot = havereboot;
break;
case 6:
allowReboot = havereboot;
allowShutdown = haveshutdown;
break;
case 7:
allowStandby = true;
break;
case 8:
allowSuspend = havesuspend;
break;
case 9:
allowExit = true;
allowSuspend = havesuspend;
break;
}
MythScreenStack *ss = GetMythMainWindow()->GetStack("popup stack");
auto *dlg = new MythDialogBox(tr("Do you really want to exit MythTV?"), ss,
"exit prompt");
if (!dlg->Create())
{
LOG(VB_GENERAL, LOG_ERR, "Can't create Exit Prompt dialog?");
delete dlg;
DoQuit();
return;
}
dlg->AddButton(QCoreApplication::translate("(Common)", "No"));
if (allowExit)
dlg->AddButton(tr("Yes, Exit now"), SLOT(DoQuit()));
if (allowReboot)
dlg->AddButton(tr("Yes, Exit and Reboot"), SLOT(ConfirmReboot()));
if (allowShutdown)
dlg->AddButton(tr("Yes, Exit and Shutdown"), SLOT(ConfirmHalt()));
if (allowStandby)
dlg->AddButton(tr("Yes, Enter Standby Mode"), SLOT(DoStandby()));
if (allowSuspend)
dlg->AddButton(tr("Yes, Suspend"), SLOT(ConfirmSuspend()));
// This is a hack so that the button clicks target the correct slot:
dlg->SetReturnEvent(this, QString());
ss->AddScreen(dlg);
}
void ExitPrompter::Confirm(MythPower::Feature Action) const
{
MythScreenStack *ss = GetMythMainWindow()->GetStack("popup stack");
QString msg;
gContext->SetDisableEventPopup(true);
if (!gCoreContext->IsFrontendOnly())
{
// this is the only case where a prompt should be shown
msg.prepend(tr("Mythbackend is running on this system. "));
auto *dlg = new MythConfirmationDialog(ss, msg);
if (!dlg->Create())
{
delete dlg;
DoQuit();
return;
}
if (Action == MythPower::FeatureShutdown)
connect(dlg, &MythConfirmationDialog::haveResult, this, &ExitPrompter::DoHalt);
else if (Action == MythPower::FeatureRestart)
connect(dlg, &MythConfirmationDialog::haveResult, this, &ExitPrompter::DoReboot);
else if (Action == MythPower::FeatureSuspend)
connect(dlg, &MythConfirmationDialog::haveResult, this, &ExitPrompter::DoSuspend);
ss->AddScreen(dlg);
}
else
{
// no prompts required, take a specific action required
// calling these exitprompter functions with (true) fails build
if (Action == MythPower::FeatureShutdown)
DoHalt(true);
else if (Action == MythPower::FeatureRestart)
DoReboot(true);
else if (Action == MythPower::FeatureSuspend)
DoSuspend(true);
}
gContext->SetDisableEventPopup(false);
}
I have already tried adding const to the end of the DoHalt (etc) functions like:
void ExitPrompter::DoHalt(const bool Confirmed) const
void ExitPrompter::DoReboot(const bool Confirmed) const
void ExitPrompter::DoSuspend(const bool Confirmed) const
But this just gives me a different error during build like:
cd mythshutdown/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake -o Makefile /home/runner/work/mythtv/mythtv/mythtv/programs/mythshutdown/mythshutdown.pro QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake ) && make -f Makefile
exitprompt.cpp:39:6: error: prototype for ‘void ExitPrompter::DoHalt(bool) const’ does not match any in class ‘ExitPrompter’
void ExitPrompter::DoHalt(const bool Confirmed) const
^~~~~~~~~~~~
In file included from exitprompt.cpp:6:0:
exitprompt.h:14:10: error: candidate is: void ExitPrompter::DoHalt(bool)
Makefile:4570: recipe for target 'obj/exitprompt.o' failed
void DoHalt(bool Confirmed = true);
make[2]: Leaving directory '/home/runner/work/mythtv/mythtv/mythtv/programs/mythfrontend'
^~~~~~
Makefile:89: recipe for target 'sub-mythfrontend-make_first' failed
exitprompt.cpp:70:6: error: prototype for ‘void ExitPrompter::DoReboot(bool) const’ does not match any in class ‘ExitPrompter’
void ExitPrompter::DoReboot(const bool Confirmed) const
^~~~~~~~~~~~
In file included from exitprompt.cpp:6:0:
exitprompt.h:15:10: error: candidate is: void ExitPrompter::DoReboot(bool)
void DoReboot(bool Confirmed = true);
^~~~~~~~
exitprompt.cpp:100:6: error: prototype for ‘void ExitPrompter::DoSuspend(bool) const’ does not match any in class ‘ExitPrompter’
void ExitPrompter::DoSuspend(const bool Confirmed) const
^~~~~~~~~~~~
In file included from exitprompt.cpp:6:0:
exitprompt.h:17:10: error: candidate is: void ExitPrompter::DoSuspend(bool)
void DoSuspend(bool Confirmed = true);
^~~~~~~~~
exitprompt.cpp: In member function ‘void ExitPrompter::Confirm(MythPower::Feature) const’:
exitprompt.cpp:268:22: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoHalt(true);
^
In file included from exitprompt.cpp:6:0:
exitprompt.h:14:10: note: in call to ‘void ExitPrompter::DoHalt(bool)’
void DoHalt(bool Confirmed = true);
^~~~~~
exitprompt.cpp:270:24: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoReboot(true);
^
In file included from exitprompt.cpp:6:0:
exitprompt.h:15:10: note: in call to ‘void ExitPrompter::DoReboot(bool)’
void DoReboot(bool Confirmed = true);
^~~~~~~~
exitprompt.cpp:272:25: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoSuspend(true);
^
In file included from exitprompt.cpp:6:0:
exitprompt.h:17:10: note: in call to ‘void ExitPrompter::DoSuspend(bool)’
void DoSuspend(bool Confirmed = true);
^~~~~~~~~
make[2]: *** [obj/exitprompt.o] Error 1
make[1]: *** [sub-mythfrontend-make_first] Error 2
I don't know C++ (I though the change I was making was fairly simple!) very well at all so I need some precise help.
Thanks

Error in Using Root/C++: No matching constructor for initialization of 'TTree'

I am trying to plot the invariant mass of the Z boson from two decayed muons. I am using MadGraph and Root. MadGraph simulates the events (p p > Z > mu+ and mu-) and creates a .root file that contains the events. I called the simulation eventgeneration.
To use Root to analyze the data and draw the histogram, I have to write my code in C++. Here is the code:
#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TH1F.h"
#include <iostream>
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#include "external/ExRootAnalysis/ExRootResult.h"
#else
class ExRootTreeReader;
class ExRootResult;
using namespace std;
#endif
void readEvents(const char *inputFile)
{
gSystem->Load("libDelphes");
TChain chain("Delphes");
chain.Add(inputFile);
ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
Long64_t numberOfEntries = treeReader->GetEntries();
TTree *tree = new TTree(&chain);
TClonesArray *branchMuon = treeReader->UseBranch("Muon");
//Long64_t numberOfMuons = branchMuon->GetEntries();
TClonesArray *branchElectron = treeReader->UseBranch("Electron");
Long64_t numberOfElectrons = branchElectron->GetEntries();
cout << "There are " << numberOfEntries << " entries in your ntuple" << endl;
UInt_t Muons;
Float_t MuonEta1;
Float_t MuonPhi1;
Float_t MuonPt1;
Float_t MuonEta2;
Float_t MuonPhi2;
Float_t MuonPt2;
tree->SetBranchAddress("MuonEta1", &MuonEta1);
tree->SetBranchAddress("MuonPhi1", &MuonPhi1);
tree->SetBranchAddress("MuonPt1", &MuonPt1);
tree->SetBranchAddress("MuonEta2", &MuonEta2);
tree->SetBranchAddress("MuonPhi2", &MuonPhi2);
tree->SetBranchAddress("MuonPt2", &MuonPt2);
TH1F *histDiMuonMass = new TH1F("mass", "M_{inv}(mu+[1], mu-[2]); M_inv (GeV/c^2); Events", 50, 0.0, 1500);
for(Int_t entry = 0; entry < numberOfEntries; ++entry)
{
treeReader->ReadEntry(entry);
Long64_t numberOfMuons = branchMuon->GetEntries();
//Muons += entry;
//Muon *muon1, *muon2, *muon3, *muon4;
TLorentzVector muon1;
TLorentzVector muon2;
muon1.SetPtEtaPhiM(MuonPt1, MuonEta1, MuonPhi1, 0.1);
muon2.SetPtEtaPhi(MuonPt2, MuonEta2, MuonPhi2, 0.1);
if(branchMuon->GetEntries() == 4)
{
TLorentzVector Z = muon1 + muon2;
histDiMuonMass->Fill(Z.M());
}
}
cout << "There are " << Muons << " entries in your ntuple" << endl;
histDiMuonMass->Draw();
}
Then in the root terminal I type: \
.x examples/readEvents.C("../eventgeneration/Events/run_01/tag_1_delphes_events.root")
However, I get the following error:
In file included from input_line_1563:1:
/mnt/c/1/MG5_aMC_v2_6_6/Delphes/examples/readEvents.C:30:20: error: no matching constructor for initialization of 'TTree'
TTree *tree = new TTree(&chain);
^ ~~~~~~
/home/cucip/builddir/include/TTree.h:295:4: note: candidate constructor not viable: no known conversion from 'TChain *' to 'const TTree' for 1st argument; remove &
TTree(const TTree& tt) = delete;
^
/home/cucip/builddir/include/TTree.h:291:4: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
TTree();
^
/home/cucip/builddir/include/TTree.h:292:4: note: candidate constructor not viable: requires at least 2 arguments, but 1 was provided
TTree(const char* name, const char* title, Int_t splitlevel = 99, TDirectory* dir = gDirectory);
^
In file included from input_line_1563:1:
/mnt/c/1/MG5_aMC_v2_6_6/Delphes/examples/readEvents.C:72:8: error: no member named 'SetPtEtaPhi' in 'TLorentzVector'
muon2.SetPtEtaPhi(MuonPt2, MuonEta2, MuonPhi2, 0.1);
Does anybody see what could cause this error and how I can fix it?
Many thanks!
By calling new TTree(&chain) you're trying to call a constructor for a TTree and you provide it with a TChain * (the type of chain is TChain, so &chain is a pointer to a TChain).
The constructors for TTree https://root.cern/doc/v618/classTTree.html take either no argument or two const char* (usually string literals or .Data() of a TString or .c_str() of a std::string or the output of ROOT's Form …).
It looks like you try to call the deleted constructor TTree(const TTree&tt)=delete, which doesn't work for several reasons:
you're providing a pointer to a TTree instead of a TTree by reference (not even sure from the top of my head if casting from TChain to TTree would work if the & wasn't there.
the constructor is deleted, so it doesn't actually exist and cannot be called.
However, from the looks of it, you want to use your TChain as a TTree*, which doesn't require any code from your side to begin with because a TChain already is a TTree by inheritance. So, you can use chain. instead of tree->, or (if having a pointer variable is really more desirable for reasons that I don't see in the example) create a TTree* (i.e. create only the pointer to a TTree, instead of creating the actual TTree on the heap and get a pointer to it from the new operator) by doing something like
TTree* tree = &chain;

"No matching function for call" in constructor

I have a MenuItem class declared like this
typedef byte (menuFn)(void); //does the things
typedef String (updateFn)(void); //updates the display string
class MenuItem {
public:
MenuItem(String dString, menuFn *onCkFn, updateFn *onUpdFn, bool clickable);
byte click(void);
void update(void);
String getDisplayString(void);
void setDisplayString(String);
private:
String _displayString;
bool _isClickable;
menuFn *_onClickFn;
updateFn *_onUpdateFn;
};
MenuItem constructor:
MenuItem::MenuItem(String dString, menuFn *onCkFn, updateFn *onUpdFn, bool clickable)
{
_displayString = dString;
_isClickable = clickable;
_onClickFn = onCkFn;
_onUpdateFn = onUpdFn;
}
which is then used in another class Menu, like this:
class Menu{
public:
Menu(MenuItem menuItems[4], MenuItem staticItems[2]);
void setItem(String itemText, byte num, menuFn itemClickFn, updateFn itemUpdateFn, bool itemClickable);
void display(void);
byte doItem(byte buttonPressed);
private:
MenuItem _menuItems[4];
MenuItem _staticItems[2];
};
and here is the Menu constructor:
Menu::Menu(MenuItem theMenuItems[4], MenuItem theStaticItems[2])
{
for (byte i = 0; i < 4; i++)
{
_menuItems[i] = theMenuItems[i];
}
for (byte i = 0; i < 2; i++)
{
_staticItems[i] = theStaticItems[i];
}
}
When I go to compile I get this error:
[..]\Menu.cpp: In constructor 'Menu::Menu(MenuItem)':
Menu.cpp:7: error: no matching function for call to 'MenuItem::MenuItem()'
Menu::Menu(MenuItem theMenuItems[4], MenuItem theStaticItems[2])
^
[..]\Menu.cpp:7:33: note: candidates are:
In file included from [..]\Menu.h:5:0,
from [..]\Menu.cpp:3:
[..]\MenuItem.h:11:3: note: MenuItem::MenuItem(String, byte (*)(), String (*)(), bool)
MenuItem(String dString, menuFn *onCkFn, updateFn *onUpdFn, bool clickable);
^
[..]\MenuItem.h:11:3: note: candidate expects 4 arguments, 0 provided
The error seems to point to me needing to give the parameters for the MenuItems when I declare the Menu. I don't understand how that would work, since they're not known until I make some menuItem Instances and then make a Menu instance to contain them.
This is using the Arduino IDE BTW, so it's c++ (ish).

How to call a class within a function definition in c++

Its my first time asking for help on programming. I have been working on a register program for my programming class for weeks which involves classes. Its rather frustrating for me. I have to use two classes: StoreItem and Register. StoreItem deals with the small list of items that the store sells. The register class deals mostly with processing the items, making a total bill and asking the user to pay with cash.
Here is the StoreItem.cpp file:
//function definition
#include <string>
#include <iostream>
#include "StoreItem.h"
#include "Register.h"
using namespace std;
StoreItem::StoreItem(string , double)
{
//sets the price of the current item
MSRP;
}
void StoreItem::SetDiscount(double)
{
// sets the discount percentage
MSRP * Discount;
}
double StoreItem::GetPrice()
{ // return the price including discounts
return Discount * MSRP;
}
double StoreItem::GetMSRP()
{
//returns the msrp
return MSRP;
}
string StoreItem::GetItemName()
{
//returns item name
return ItemName;
}
StoreItem::~StoreItem()
{
//deletes storeitem when done
}
Here is the Register.cpp:
Note that the last 5 function definitions in this one arent finished yet...
// definition of the register header
#include "Register.h"
#include "StoreItem.h"
using namespace std;
Register::Register()
{ // sets the initial cash in register to 400
CashInRegister = 400;
}
Register::Register(double)
{ //accepts initial specific amount
CashInRegister ;
}
void Register::NewTransAction()
{ //sets up the register for a new customer transaction (1 per checkout)
int NewTransactionCounter = 0;
NewTransactionCounter++;
}
void Register::ScanItem(StoreItem)
{ // adds item to current transaction
StoreItem.GetPrice();
// this probably isnt correct....
}
double Register::RegisterBalance()
{
// returns the current amount in the register
}
double Register::GetTransActionTotal()
{
// returns total of current transaction
}
double Register::AcceptCash(double)
{
// accepts case from customer for transaction. returns change
}
void Register::PrintReciept()
{
// Prints all the items in the transaction and price when finsished
}
Register::~Register()
{
// deletes register
}
My main question is where Register::ScanItem(StoreItem)... is there a way to correctly call a function from the storeItem Class into the Register scanitem function?
You have:
void Register::ScanItem(StoreItem)
{ // adds item to current transaction
StoreItem.GetPrice();
// this probably isnt correct....
}
This means that the ScanItem function takes one argument of type StoreItem. In C++ you can specify just the type and make the compiler happy. But if you intend to use the argument, you must give it a name. For example:
void Register::ScanItem(StoreItem item)
{
std::cout << item.GetItemName() << " costs " << item.GetPrice() << std::endl;
}
To be able to call a member function of the object you're passing as the parameter, you need to name the parameter, not just its type.
I suspect you want something like
void Register::ScanItem(StoreItem item)
{
total += item.GetPrice();
}

Displaying a value in a text box-Error

I have
size_t sums[4] = {0, 0, 0, 0};
and a text box in which I am trying to display the value that I get after I've done some operations on it. The value is in sums[i] , however now I want to display the value in the textbox, I am doing this:
*TextBox4 << "hello" << size_t sums;
frame->Connect(TEXT_BOX4, wxEVT_COMMAND_BUTTON_CLICKED | wxEVT_COMMAND_ENTER, (wxObjectEventFunction) & MyFrame::OnGenerateKey);
TextBox4 = new wxTextCtrl(this, TEXT_BOX4, wxT(""), wxPoint(200, 200), wxSize(200, 20), wxTE_PROCESS_ENTER | wxTE_READONLY | wxTE_LEFT, wxDefaultValidator, wxT("WxTextBox4"));
however it generates the following errors
base.cpp:212:22: error: ambiguous overload for 'operator<<' in '*((MyFrame*)this)->MyFrame::TextBox4 << sum'
base.cpp:212:22: note: candidates are:
C:\wxWidgets-2.8.12\include/wx/textctrl.h:419:17: note: wxTextCtrl& wxTextCtrlBase::operator<<(const wxString&)
C:\wxWidgets-2.8.12\include/wx/textctrl.h:420:17: note: wxTextCtrl& wxTextCtrlBase::operator<<(int)
C:\wxWidgets-2.8.12\include/wx/textctrl.h:421:17: note: wxTextCtrl& wxTextCtrlBase::operator<<(long int)
C:\wxWidgets-2.8.12\include/wx/textctrl.h:422:17: note: wxTextCtrl& wxTextCtrlBase::operator<<(float)
C:\wxWidgets-2.8.12\include/wx/textctrl.h:423:17: note: wxTextCtrl& wxTextCtrlBase::operator<<(double)
C:\wxWidgets-2.8.12\include/wx/textctrl.h:424:17: note: wxTextCtrl& wxTextCtrlBase::operator<<(wxChar)
Please help me.
First of all you can not print a static array like that, you need to iterate over it. Second - you should only print sums without the type:
*TextBox4 << "hello" << sums;
Still this may not be enough to help you - I need more context.