c++ - initializing class A (with a reference member) within class B -


i'm trying make simple currency converter , have problems class designed make calculations. want create object of class in mainwindow use total variable displaying result in widget on appi form.

member functions aren't here yet, problem have 'calculator' : no appropriate default constructor available error in mainwindow.cpp

while know means, don't know how avoid (solve) issue because kind of need reference on map echange rates needed.

.cpp

#include <qobject> #include <qstring> #include <qdebug> #include <ui_mainwindow.h>  class calculator { public:     explicit calculator(qmap<qstring,double> &currency_map);     void multiply(double x, double y);     void getvalues(qstring strfrom, qstring strto);  private:     double total, firstcurr, secondcurr;     qmap<qstring,double> &map; }; 

.h

#include "calculator.h"  calculator::calculator(qmap<qstring,double> &currency_map):map(currency_map) {     total = 0;     firstcurr = 0;     secondcurr= 0; }  void calculator::getvalues(qstring strfrom, qstring strto) {       qmapiterator<qstring, double> i(map);     while(i.hasnext())         {             if(i.key() == strfrom)                 firstcurr=i.value();             if(i.key() == strto)                 secondcurr = i.value();     } }  void calculator::multiply(double x, double y) {     total = x * y; } 

and im trying create object of class in mainwindow class:

#include <qmainwindow> #include <ui_mainwindow.h> #include "calculator.h"  namespace ui { class mainwindow; }  class mainwindow : public qmainwindow {     q_object  public:     explicit mainwindow(qmap<qstring,double> &currency_map, qwidget *parent = 0);      ~mainwindow();  private:     ui::mainwindow *ui;     parser currency_parser;     calculator calc; // error  }; 

mainwindow.h

mainwindow::mainwindow(qmap<qstring, double> &currency_map, qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);      ui->from_combox->additems(currency_parser.currency_list);     ui->to_combox->additems(currency_parser.currency_list); } 

the idea behind have map in main in save data needed , pass map around classes use it.

i'll post main tho im not sure if it's needed

#include "downloader.h" #include "mainwindow.h" #include "parser.h" #include "calculator.h" #include <qapplication>   int main(int argc, char *argv[]) {     qapplication a(argc, argv);      qmap<qstring,double> currency_map;      downloader d;     d.do_download();      parser p;     p.read_line(currency_map);      mainwindow w(currency_map);     w.show();      return a.exec(); }; 

the error occurs, because don't specify appropriate constructor class calculator in mainwindow constructors member initializer list (the compiler want's use default constructor then):

mainwindow::mainwindow(qmap<qstring, double> &currency_map, qwidget *parent) : qmainwindow(parent) , ui(new ui::mainwindow) , calc(currency_map) // <<<<<<<<<<<<<< {     // ... } 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -