vendredi 11 février 2022

E0153 - expression must have class type but it has type "void"

I have been trying to make my program work but I have run into an issue.

The error I get on Visual Studio is: expression must have class type but it has type "void"

The error comes from my main.cpp file on line 24:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include "Robot.h"

using namespace std;
using namespace sdds;

int main()
{
    const int num_robots = 6;
    int broken_robot = 0;
    char replacmentName[] = "C3PO";
    Robot robot[num_robots] = {
        {},
        {"KC1", "kitchen", 25.33, 4.55, 2, 2.2, false},
        {"BR1", "bedroom", 5.22, 2.54, 1, 2.2, true},
        {"Broken", "Bedroom", 10.12, 2.5,1.55, 0, true},
        {"KC2", "kitchen", 20.56, 5, 2, 3.5, true},
        {"BR2", "bedroom", 25.32, 6.5, 2.5, 3.1, true}
    };

    while ((broken_robot = conrtolRooomReport(robot, num_robots)) >= 0) {
        cout << endl << "Attention: There is a broken robot! Fixing the problem..." << endl;
        robot[broken_robot].set(replacmentName, "Control Room", 10.0, 4, 1, 2.09, false).display();
        replacmentName[0]++;
        cout << "Replacement Provided!" << endl << endl;
    }

    return 0;
}

The Robot.h header file:

#ifndef _ROBOT_H
#define _ROBOT_H
namespace sdds {
    class Robot {
        char* name;
        char* location;
        double weight;
        double width;
        double height;
        double speeed;
        bool deployed;
    public:
            // Constructs & Destructor:
        Robot();
        Robot(const char* newName, const char* newLoc, double newWeight, double newWidth, double newHeight, double newSpeed, bool deploy);
        ~Robot();
            // Queries:
        char* getName() const;
        char* getLocation() const;
        bool isDeployed() const;
        bool isValid() const;
        double speed() const;
        void display() const;
            // Modifiers
        void set(const char* newName, const char* newLoc, double newWeight, double newWidth, double newHeight, double newSpeed, bool deploy);
        void setLocation(char* newestLoc);
        void setDeployed(bool deploy);
    };
            // Other Functions:
    int conrtolRooomReport(const Robot robot[], int num_robots);
}
#endif

display() function implementation:

void Robot::display() const{
    cout << "| ";
    cout.setf(ios::left);
    cout.width(10);
    cout << name << " | ";
    cout.width(15);
    cout << location << " | ";
    cout.setf(ios::right);
    cout.setf(ios::fixed);
    cout.width(6);
    cout << setprecision(1) << weight << " | ";
    cout.width(6);
    cout << setprecision(1) << width << " | ";
    cout.width(6);
    cout << setprecision(1) << height << " | ";
    cout.width(6);
    cout << setprecision(1) << speeed << " | ";
    cout.width(8);
    cout.unsetf(ios::right);
    cout.setf(ios::left);
    if(isDeployed() == true)
        cout << "YES" << " |" << endl;
    else
        cout << "NO" << " |" << endl;
    cout.unsetf(ios::left);
}

set() function implementation:

void Robot::set(const char* newName, const char* newLoc, double newWeight, double newWidth, double newHeight, double newSpeed, bool deploy) {
    if (newName[0] != '\0' && newName != nullptr && newLoc[0] != '\0' && newLoc != nullptr && newWeight > 0.00 && newWidth > 0.00 && newHeight > 0.00 && newSpeed > 0.00) {
        name = new char[strlen(newName) + 1];
        strcpy(name, newName);
        location = new char[strlen(newLoc) + 1];
        strcpy(location, newLoc);
        weight = newWeight;
        width = newWidth;
        height = newHeight;
        speeed = newSpeed;
        deployed = deploy;
    }
}

Any help would be much appreciated. Tried scouring through Google but couldn't find a solution.

Aucun commentaire:

Enregistrer un commentaire