My object is producting an error. Cannot figure out what is wrong.

I created two header files w/ their corresponding .cpp file and one main. I created one object called Resistor_4Band Resistor4 and another called Resistor _5_Band Resistor 5. It is saying that it is not recognizing Resistor_5_Band as a type at all and keeps wanting me to replace it with Resistor_4Band.

I've included my main and two header files 4Band.h and 5Band.h. Let me know if i need to paste in my .cpp files for both headers.

Also the first error is on the line where I declared the object Resistor5. The other errors are on the lines that contain every function call belonging to Resistor5. All header files and .cpp files seem to be ok. No errors show there. main is the only place where these errors are coming up.

Errors:

1
2
3
4
5
6
7
8
9
Resistor_Trial_2 Group
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp:15:5: Unknown type name 'Resistor_5_Band'; did you mean 'Resistor_4Band'?
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp:63:23: No member named 'set_Resistor_5_Colors' in 'Resistor_4Band'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp:64:23: No member named 'set_Resistor_5_Values' in 'Resistor_4Band'; did you mean 'Resistor4_Value'?
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp:64:44: Called object type 'float' is not a function or function pointer
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp:65:23: No member named 'calculate_Resistor_5_Value' in 'Resistor_4Band'; did you mean 'calculate_Resistor4_Value'?
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp:66:23: No member named 'print_Resistor_5_Value' in 'Resistor_4Band'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Resistor_Trial_2/Resistor_Trial_2/main.cpp:67:24: Identifier 'Resistor_5_Band' in object destruction expression does not name a type


MAIN:

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
//
//  main.cpp
//  Resistor_Trial_2
//
//  Created by Shane Yost on 3/26/13.
//  Copyright (c) 2013 Shane Yost. All rights reserved.
//

#include "4Band.h"
#include "5Band.h"

int main()
{
    Resistor_4Band Resistor4;
    Resistor_5_Band Resistor5;
    char choice;
    string c4[4];
    string c5[5];
    for (int i = 0; i < 4; i++) {
        c4[i] = " ";
    }
    for (int i = 0; i < 5; i++) {
        c5[i] = " ";
    }
    cout << "\t____________ MAIN MENU ____________\n\n"
         << "\t\t(a)--->4BAND RESISTOR\n"
         << "\t\t(b)--->5BAND RESISTOR\n"
         << "\t\t(c)--->6BAND RESISTOR\n"
         << "\t\t(d)--->EXIT PROGRAM\n"
         << "\t___________________________________\n\n"
         << "\tCHOOSE A SELECTION: ";
    cin >> choice;
    switch (choice) {
        case 'a':
            cout << "\n\nEnter Color of Band 1: ";
            cin >> c4[0];
            cout << "\n\nEnter Color of Band 2: ";
            cin >> c4[1];
            cout << "\n\nEnter Color of Band 3: ";
            cin >> c4[2];
            cout << "\n\nEnter Color of Band 4: ";
            cin >> c4[3];
            cout << "\n\n";
            Resistor4.set_Band4_Colors(c4[0],c4[1],c4[2],c4[3]);
            Resistor4.set_Band4_Values();
            Resistor4.set_Band4_Tolerance();
            Resistor4.calculate_Resistor4_Value();
            Resistor4.print_Resistor4();
            Resistor4.~Resistor_4Band();
            break;
        case 'b':
            cout << "\n\nEnter Color of Band 1: ";
            cin >> c5[0];
            cout << "\n\nEnter Color of Band 2: ";
            cin >> c5[1];
            cout << "\n\nEnter Color of Band 3: ";
            cin >> c5[2];
            cout << "\n\nEnter Color of Band 4: ";
            cin >> c5[3];
            cout << "\n\nEnter Color of Band 5: ";
            cin >> c5[4];
            cout << "\n\n";
            Resistor5.set_Resistor_5_Colors(c5[0],c5[1],c5[2],c5[3],c5[4]);
            Resistor5.set_Resistor_5_Values();
            Resistor5.calculate_Resistor_5_Value();
            Resistor5.print_Resistor_5_Value();
            Resistor5.~Resistor_5_Band();
            break;   
        default:
            break;
    }
    return 0;
}




4Band.h

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
#ifndef __Resistor_Trial_2___Band__
#define __Resistor_Trial_2___Band__

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
class Resistor_4Band{
    
private:
    
    string Band4_Colors[4];
    float Band4_Values[3];
    float Band4_Tolerance;
    string ohms;
    string tol;
    float Resistor4_Value;
    
public:
    
    Resistor_4Band();
    ~Resistor_4Band();
    
    void set_Band4_Colors(string,string,string,string);
    void set_Band4_Values();
    void set_Band4_Tolerance();
    
    float get_Band1_Value();
    float get_Band2_Value();
    float get_Band3_Value();
    
    float get_Band4_Tolerance();
    
    string get_Band1_Color();
    string get_Band2_Color();
    string get_Band3_Color();
    string get_Band4_Color();
    
    void print_Resistor4();
    void calculate_Resistor4_Value();
};
#endif /* defined(__Resistor_Trial_2___Band__) */ 



5Band.h

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
#ifndef __Resistor_Trial_2___Band__
#define __Resistor_Trial_2___Band__

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
class Resistor_5_Band{
private:
    
    string Resistor_5_Colors[5];
    float Resistor_5_Values[5];
    string ohms;
    string tol;
    float Resistor_5_Value;
    
public:
    
    Resistor_5_Band();
    ~Resistor_5_Band();
    
    void set_Resistor_5_Colors(string, string, string, string,string);
    void set_Resistor_5_Values();

string get_Band1_Color();
string get_Band2_Color();
string get_Band3_Color();
string get_Band4_Color();
string get_Band5_Color();

float get_Band1_Value();
float get_Band2_Value();
float get_Band3_Value();
float get_Band4_Value();
float get_Band5_Value();

void print_Resistor_5_Band();
void calculate_Resistor_5_Value();

};

#endif /* defined(__Resistor_Trial_2___Band__) */ 


You used the same header guard for both 4Band.h and 5Band.h so your class Resistor_5_Band is never seen.
So I have to many of the same members, functions, in both classes?

How do I go about fixing this?
When compiling main.cpp:

After the line #include "4Band.h" has been processed the compiler has seen your class Resistor_4Band and the macro __Resistor_Trial_2___Band__ is defined. Now when the #include "5Band.h" line is processed, because the macro is already defined, everything in 5Band.h is skipped down to the #endif statement so the compiler never sees your Resistor_5_Band class. To fix this you need to use different macros in the header guards of each file. Change one of them to something different.
Topic archived. No new replies allowed.