C2676 error in Visual 2019 C++H

Hello!

I keep getting this error no matter what I change and I can solve it

Error C2676 binary '==': 'tipAplicatie' does not define this operator or a conversion to a type acceptable to the predefined operator UnitTests C: 25


My code:
class Autoturism
{
public:
string marca;
string model;
char numarInmatriculare[9];
int putere;
double pret;

You need to provide the compilable code that produces the error. Your 'code' is just the start of a class.


This is the code I wrote


#include <iostream>
#include <string>
using namespace std;
bool fisierDeschis = true;

enum class tipAplicatie {
aplicatieWeb = 5,
aplicatieMobila = 10,
aplicatieDesktop = 15,
NONE = 0,
};

class Autoturism
{
public:
string marca;
string model;
char numarInmatriculare[9];
int putere;
double pret;


class Autoturism()
{


marca = "Necunoscuta";
model = "Necunoscut";
putere = 0;
pret = 5000;
}

Autoturism(string marca, string model, int putere)
{
this->marca =marca;
this->model = model;
this->putere = putere;
pret = 5000;
}

void discount(int procent)
{
if (procent >= 1 && procent <= 50)
{
pret = pret * (procent / 100.0);
}
}

void seteazaNumarInmatriculare(char numar[])
{
if (strlen(numar) <= 9)
{
strcpy_s(numarInmatriculare, numar);
}
}

char* obtineNumarInmatriculare()
{
return numarInmatriculare;
}
~Autoturism()
{
fisierDeschis = false;
}
};






This is the UniTest code where the error appear a

tipAplicatie rezultat = modificare_enum("aplicatieWeb");
Assert::IsTrue(rezultat == 5, L"Functia nu seteaza corect o aplicatie web");
rezultat = modificare_enum("aplicatieMobila");
Assert::IsTrue(rezultat == 10, L"Functia nu seteaza corect o aplicatie mobila");
rezultat = modificare_enum("aplicatieDesktop");
Assert::IsTrue(rezultat == 15, L"Functia nu seteaza corect o aplicatie desktop");
}
1
2
3
4
5
6
7
class Autoturism()
{
marca = "Necunoscuta";
model = "Necunoscut";
putere = 0;
pret = 5000;
}


This is supposed to be the default constructor. You don't need the class modifier. All you need is:

1
2
3
4
5
6
7
Autoturism()
{
marca = "Necunoscuta";
model = "Necunoscut";
putere = 0;
pret = 5000;
}

I modified and I still get the same error
It might be something on the code? Or in the UnitTest cpp?
Last edited on
1
2
tipAplicatie rezultat = modificare_enum("aplicatieWeb");
Assert::IsTrue(rezultat == 5, L"Functia nu seteaza corect o aplicatie web");


You can't compare an enum with an int.
Try this:
 
Assert::IsTrue(rezultat == tipAplicatie::aplicatieWeb , L"Functia nu seteaza corect o aplicatie web");

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
using namespace std;
bool fisierDeschis = true;

enum class tipAplicatie {
    aplicatieWeb = 5,
    aplicatieMobila = 10,
    aplicatieDesktop = 15,
    NONE = 0,
};

class Autoturism
{
public:
    string marca;
    string model;
    char numarInmatriculare[9];
    int putere;
    double pret;
    
    
    Autoturism() // <--
    {
        
        
        marca = "Necunoscuta";
        model = "Necunoscut";
        putere = 0;
        pret = 5000;
    }
    
    Autoturism(string marca, string model, int putere)
    {
        this->marca =marca;
        this->model = model;
        this->putere = putere;
        pret = 5000;
    }
    
    void discount(int procent)
    {
        if (procent >= 1 && procent <= 50)
        {
            pret = pret * (procent / 100.0);
        }
    }
    
    void seteazaNumarInmatriculare(char numar[])
    {
        if (strlen(numar) <= 9)
        {
            strcpy(numarInmatriculare, numar); // <--
        }
    }
    
    char* obtineNumarInmatriculare()
    {
        return numarInmatriculare;
    }
    ~Autoturism()
    {
        fisierDeschis = false;
    }
};

int main()
{
    Autoturism au;
    au.discount(5);
    
    std::cout << au.marca << '\n';
    return 0;
}



Necunoscuta
Program ended with exit code: 0
againtry where you put //<-- means I should add something?
No, where I put a //<-- means where I fixed your program so it compiles and runs.
thank you very much
Topic archived. No new replies allowed.