I am trying to simulate a certain game as an exercise (dont ask me which, you will know if you know the game), however, I just learnt objects and class on the internet and the whole thing is still so confusing to me. The following is a section of my code that is giving me an error.
The error I have is:
C:\Users\N\Desktop\Untitled1.cpp In constructor 'ekop::Moveset::Moveset()':
56 9 C:\Users\N\Desktop\Untitled1.cpp [Error] no matching function for call to 'Move::Move()'
56 9 C:\Users\N\Desktop\Untitled1.cpp [Note] candidates are:
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(std::string, int, int, int)
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 4 arguments, 0 provided
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(const Move&)
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 1 argument, 0 provided
56 9 C:\Users\N\Desktop\Untitled1.cpp [Error] no matching function for call to 'Move::Move()'
56 9 C:\Users\N\Desktop\Untitled1.cpp [Note] candidates are:
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(std::string, int, int, int)
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 4 arguments, 0 provided
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(const Move&)
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 1 argument, 0 provided
56 9 C:\Users\N\Desktop\Untitled1.cpp [Error] no matching function for call to 'Move::Move()'
56 9 C:\Users\N\Desktop\Untitled1.cpp [Note] candidates are:
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(std::string, int, int, int)
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 4 arguments, 0 provided
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(const Move&)
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 1 argument, 0 provided
56 9 C:\Users\N\Desktop\Untitled1.cpp [Error] no matching function for call to 'Move::Move()'
56 9 C:\Users\N\Desktop\Untitled1.cpp [Note] candidates are:
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(std::string, int, int, int)
14 3 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 4 arguments, 0 provided
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] Move::Move(const Move&)
11 7 C:\Users\N\Desktop\Untitled1.cpp [Note] candidate expects 1 argument, 0 provided
C:\Users\N\Desktop\Untitled1.cpp In constructor 'ekop::ekop()':
52 12 C:\Users\N\Desktop\Untitled1.cpp [Note] synthesized method 'ekop::Moveset::Moveset()' first required here
I don't know what went wrong, the code is below.
Don't tell me not to use using namespace std;
, I know I am not supposed to do that but I am not going to fix that in this program.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
using namespace std;
class Move
{
public:
Move(string a, int b, int c, int d)
{
name = a;
type_num = b;
power = c;
accuracy = d;
}
void setName (string a)
{
name = a;
}
void setType_num(int a)
{
type_num = a;
}
void setPower(int a)
{
power = a;
}
void setAccuracy(int a)
{
accuracy = a;
}
private:
string name, type;
int type_num, power, accuracy;
};
class ekop
{
public:
ekop()
{
Moveset moveset;
}
private:
class Moveset
{
public:
//constructor
//retrievors
private:
Move slot1, slot2, slot3, slot4;
};
};
int main()
{
//lines of code
return EXIT_SUCCESS;
}
edit 1: I had this constructor for the class Moveset, but since it didnt affect the error when I took it out, so I didnt include that in the post just now.
Moveset()
{
slot1.setName("MOVE 1");
slot1.setType_num(rand()%18);
slot1.setPower(10*(rand%15+1));
slot1.setAccuracy(5*(rand%11+10));
//repeat for the rest of the slots
}
edit 2: Now if I do this instead:
//No change before this
class Moveset
{
public:
//constructor
//retrievors
private:
Move slot1("MOVE 1", rand() % 18, 10*(rand % 15 + 1), 5 * (rand % 11 + 10)),
slot2("MOVE 2", rand() % 18, 10*(rand % 15 + 1), 5 * (rand % 11 + 10)),
slot3("MOVE 3", rand() % 18, 10*(rand % 15 + 1), 5 * (rand % 11 + 10)),
slot4("MOVE 4", rand() % 18, 10*(rand % 15 + 1), 5 * (rand % 11 + 10));
};
};
//no change after this
I get this error instead:
62 16 C:\Users\N\Desktop\Untitled1.cpp [Error] expected identifier before string constant
62 16 C:\Users\N\Desktop\Untitled1.cpp [Error] expected ',' or '...' before string constant
63 16 C:\Users\N\Desktop\Untitled1.cpp [Error] expected identifier before string constant
63 16 C:\Users\N\Desktop\Untitled1.cpp [Error] expected ',' or '...' before string constant
64 13 C:\Users\N\Desktop\Untitled1.cpp [Error] expected identifier before string constant
64 13 C:\Users\N\Desktop\Untitled1.cpp [Error] expected ',' or '...' before string constant
65 13 C:\Users\N\Desktop\Untitled1.cpp [Error] expected identifier before string constant
65 13 C:\Users\N\Desktop\Untitled1.cpp [Error] expected ',' or '...' before string constant