0

RobotPart.h

#ifndef __ROBOTPART_H
#define __ROBOTPART_H 2016

#include <string>

class RobotPart {
public:

    RobotPart(std::string kname, int kpartNumber, double kweight, double kcost,
              std::string kdescription, int kpartType);
protected:

    std::string name;
    int partNumber;
    double weight;
    double cost;
    std::string description;
    int partType;
};
#endif

RobotPart.cpp

#include "RobotPart.h"


RobotPart::RobotPart(std::string kname, int kpartNumber, double kweight,
                     double kcost, std::string kdescription, int kpartType) : 
    name(kname), partNumber(kpartNumber), weight(kweight), cost(kcost),
    description(kdescription), partType(kpartType) {}

controller.cpp

#include "controller.h"
#include "RobotPart.h"
#include "view.h"
#include "Torso.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main () {
    View view;
    RobotPart rb;

    view.displayMenu();



    return 0;
}

Error

controller.cpp: In function ‘int main()’:
controller.cpp:26:12: error: no matching function for call to ‘RobotPart::RobotPart()’
RobotPart rb;
          ^
controller.cpp:26:12: note: candidates are:
In file included from controller.cpp:2:0:
RobotPart.h:9:3: note: RobotPart::RobotPart(std::string, int, double, double, std::string, int)
RobotPart(std::string kname, int kpartNumber, double kweight, double kcost,
^
RobotPart.h:9:3: note:   candidate expects 6 arguments, 0 provided
RobotPart.h:6:7: note: RobotPart::RobotPart(const RobotPart&)
class RobotPart {
      ^
RobotPart.h:6:7: note:   candidate expects 1 argument, 0 provided
make: *** [controller.o] Error 1

I've been working on my c++ class project about a robot shop. I'm getting this error and I've tried to look up for similar problems but I can't seem to fix it. Please help. Thank you.

yd1
  • 277
  • 4
  • 13
Misuti
  • 313
  • 1
  • 2
  • 8
  • 1
    Note: names starting with two underscores, like `__ROBOTPART_H`, are reserved to the implementation. Also, names starting with underscore followed by uppercase, as well as global namespace namespace starting with underscore. – Cheers and hth. - Alf Oct 16 '16 at 06:48
  • 1
    You have defined one constructor. It takes parameters. `RobotPart rb;` provides no parameters. `RobotPart rb{param1, param2, etc...};` will solve that. – user4581301 Oct 16 '16 at 06:49
  • 3
    You're using default initialization for a class that doesn't have a default constructor. – Cheers and hth. - Alf Oct 16 '16 at 06:49
  • 1
    Class does not have default constructor ..... need to pass the values of current constructor to make it working .....constructor mis match issues. – MD. Nazmul Kibria Oct 16 '16 at 06:52
  • Thanks guys. I fixed it just now. – Misuti Oct 16 '16 at 07:08

0 Answers0