Private & public function problem
Jul 22, 2020 at 11:03am UTC
Hello I'm learning cpp and I'm currently fiddeling with private and public functions.
I think I have missed something in my code.
Thanks for any advice
ERROR on line 43:
too few arguments to function call single argument 'x' was not specified
====
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#include <QCoreApplication>
#include <string>
#include <iostream>
using namespace std;
class MilkshakeClass{
private : // Milkshake Factory
string MilkShakeName;
// ----------------------------------------
public : // Milkshake Distributor
void setMilkshakeName (string x) {
MilkShakeName = x;
}
string getMilkshakeName(){
return MilkShakeName;
}
};
// =====================================
int main(int argc, char *argv[]) // Milkshake shop
{
QCoreApplication a(argc, argv);
MilkshakeClass MilkshakeObjekt;
cout << "Name your Milkshake \n" ;
cin >> MilkshakeObjekt.setMilkshakeName();
cout << MilkshakeObjekt.getMilkshakeName();
return a.exec();
}
Last edited on Jul 22, 2020 at 11:13am UTC
Jul 22, 2020 at 11:31am UTC
void setMilkshakeName (string x)
This function expects one parameter. A string.
How many have you passed when you tried to use the function?
MilkshakeObjekt.setMilkshakeName();
Zero. This makes no sense.
1 2 3 4
cout << "Name your Milkshake \n" ;
string userinput;
cin >> userinput;
MilkshakeObjekt.setMilkshakeName(userinput);
Jul 23, 2020 at 8:48am UTC
@Repeater,
Ah my fault I forgot. Now I understand. I'm learning. Thanks for the quick help.
I did not report your post..not sure on why it says reported.
Topic archived. No new replies allowed.