Error: Expression does not have class type

In the row 67 there is an error: 'p.MESWERT::getEinheit' does not have class type. What am I doing wrong?

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 #include <cassert>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class MESSWERT
{
private:
    double wert;
    string einheit;
public:
    MESSWERT (double w=0, string e = ""); //konstruktor
    MESSWERT (const MESSWERT &m); //kopiekostruktor
    void setMesswert (double w, string e); //setter
    double getWert(); //getter
    string getEinheit(); //getter?
    void print();
};

//kostruktor initialisation
MESSWERT::MESSWERT (double w, string e)
{
    this->wert =w;
    this->einheit = e;
}

//kopiekonstructor initialisation
MESSWERT::MESSWERT (const MESSWERT &m)
{
    this->wert = m.wert;
    this->einheit = m.einheit;
}

//getter
string MESSWERT::getEinheit()
{
    return this->einheit;
}

//setter
void MESSWERT::setMesswert(double w, string e)
{
    this->einheit = e;
}

void MESSWERT::print()
{
    cout << this->wert << " = " << this->einheit << endl;
}

int main()
{
    MESSWERT mo1(20, "uA");
    MESSWERT mo2(10, "kV");
}

//Methode ohne Parameter zu Normierung
int normieren(MESSWERT &p)
{
   // string str_temp = p.getEinheit();
	if (p.getEinheit() == "A" || p.getEinheit() == "V" || p.getEinheit() == "W")
	{
		return 0;
	}
	if (p.getEinheit.length() != 2 || p.getEinheit[1] != 'A' && p.getEinheit[1] != 'V' && p.getEinheit[1] != 'W')
	{
		return 42;
	}
	switch (p.getEinheit[0])
	{
	case 'n':
		p.getWert() *= 0.000000001;
		break;
	case 'u':
		p.getWert() *= 0.000001;
		break;
	case 'm':
		p.getWert() *= 0.001;
		break;
	case 'k':
		p.getWert() *= 1000.;
		break;
	case 'M':
		p.getWert() *= 1000000;
		break;
	default:
		return 42;
	}
	p.getEinheit = p.getEinheit.substr(1);
	return 0;
}
getEinheit is a function, it needs to be called with parentheses, like you do on line 63.
Okay, it worked, thanks a lot! There is another problem now, in hte line 74 there is an error "no matching function for call to 'MESSWERT::setMesswert()'. Do you have any idea why? Here is the code, it's a bit different now!

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <cassert>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class MESSWERT
{
private:
    double wert;
    string einheit;
public:
    MESSWERT (double w=0, string e = ""); //konstruktor
    MESSWERT (const MESSWERT &m); //kopiekostruktor
    void setMesswert (double w, string e); //setter
    double getWert(); //getter
    string getEinheit(); //getter?
    void print();
};

//kostruktor initialisation
MESSWERT::MESSWERT (double w, string e)
{
    this->wert =w;
    this->einheit = e;
}

//kopiekonstructor initialisation
MESSWERT::MESSWERT (const MESSWERT &m)
{
    this->wert = m.wert;
    this->einheit = m.einheit;
}

//getter
string MESSWERT::getEinheit()
{
    return this->einheit;
}

//setter
void MESSWERT::setMesswert(double w, string e)
{
    this->einheit = e;
}

void MESSWERT::print()
{
    cout << this->wert << " = " << this->einheit << endl;
}

int main()
{
    MESSWERT mo1(20, "uA");
    MESSWERT mo2(10, "kV");
}

//Methode ohne Parameter zu Normierung
int normieren(MESSWERT &p)
{

	if (p.getEinheit() == "A" || p.getEinheit() == "V" || p.getEinheit() == "W")
	{
		return 0;
	}
	if (p.getEinheit().length() != 2 || p.getEinheit()[1] != 'A' && p.getEinheit()[1] != 'V' && p.getEinheit()[1] != 'W')
	{
		return 42;
	}
	switch (p.getEinheit()[0])
	{
	case 'n':
		p.setMesswert=(p.setMesswert() * 0.000000001);
		break;
	case 'u':
		p.setMesswert(p.setMesswert() * 0.000001);
		break;
	case 'm':
		p.setMesswert(p.setMesswert() * 0.001);
		break;
	case 'k':
		p.setMesswert(p.setMesswert() * 1000);
		break;
	case 'M':
		p.setMesswert(p.setMesswert() * 1000000);
		break;
	default:
		return 42;
	}
	p.getEinheit() = p.getEinheit().substr(1);
	return 0;
}
Just another typo. Look closely. What makes line 74 different than line 77, or 80, besides the constant factor?

Remove the equals sign.
Yeah, you're right, but it doesnt work anyway, I get errors in the lines 74, 77, 80, 83 and 86, saying 'no matching function for call to 'MESSWERT::setMesswert (double)'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
switch (p.getEinheit()[0])
	{
	case 'n':
		p.setMesswert(p.getWert() * 0.000000001);
		break;
	case 'u':
		p.setMesswert(p.getWert() * 0.000001);
		break;
	case 'm':
		p.setMesswert(p.getWert() * 0.001);
		break;
	case 'k':
		p.setMesswert(p.getWert() * 1000);
		break;
	case 'M':
		p.setMesswert(p.getWert() * 1000000);
		break;
	default:
saying 'no matching function for call to 'MESSWERT::setMesswert (double)'

void MESSWERT::setMesswert(double w, string e)

the compiler is correct. it takes (double, string). ^^^ and, in fact, it uses the string but not the double.
Last edited on
Okay, thanks jonnin my man, how do I correct that?
Nevermind, it's solved

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
switch (p.getEinheit()[0])
	{
	case 'n':
		p.setMesswert(p.getWert() * 0.000000001, "");
		break;
	case 'u':
		p.setMesswert(p.getWert() * 0.000001, "");
		break;
	case 'm':
		p.setMesswert(p.getWert() * 0.001, "");
		break;
	case 'k':
		p.setMesswert(p.getWert() * 1000, "");
		break;
	case 'M':
		p.setMesswert(p.getWert() * 1000000, "");
		break;
	default:
		return 42;
It might compile, but it still doesn't make sense. Are you just copying this from somewhere, without understanding what it's supposed to be doing?

Your function is called setMesswert, yet you set einheit, not wert.
Last edited on
Topic archived. No new replies allowed.