Finding Error Passing Classes around

Ok i have just started using classes and headers in programs and this is the first pass at it. I am getting an error code that does not give me any hint to the problem.. it is probably a stupid one too.
the error code is

obj\Debug\main.o
In function 'ZN5GenieC1Ev':

obj\Debug\Genie.o:C:\MinGW\Bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_factes.tcc
line 2497 first defined here

I am not sure if i am using the class pointers right. I think it has something to do with printMenu(quit, genie);

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
95
96
97
98
99
100
#include "Genie.h"

void Genie::affirmLife()
{
    cout << '\n' << name << " says hello\n\n";
}

string Genie::giveFortune ()
{
    string fortune[20] = {
    "As I see it, yes",
    "It is certain",
    "It is decidedly so",
    "Most likely",
    "Outlook good",
    "Signs point to yes",
    "Without a doubt",
    "Yes",
    "Yes - definitely",
    "You may rely on it",
    "Reply hazy, try again",
    "Ask again later",
    "Better not tell you now",
    "Cannot predict now",
    "Concentrate and ask again",
    "Don't count on it",
    "My reply is no",
    "My sources say no",
    "Outlook not so good",
    "Very doubtful"};
    cout << "Ask me your question and I will tell you my Answer.\n";
    string quest = reader.readString();
    int outcome = rand () % 20 + 1;
    return fortune[outcome];
}

void Genie::calorie ()
{
    int weight,height,age;
    char gender;
    float bmr, activity;
    cout << "Please tell me how much you weigh. In pounds.(60-400)\n";
    weight = reader.readInt(60,400);
    cout << "Please tell me how tall you are. In inches.(38-84)\n";
    height = reader.readInt(38,84);
    cout << "Please tell me how old you are. In years.\n";
    age = reader.readInt(1,100);
    cout << "Please tell me your gender. (M/F)\n";
    gender = reader.readChar("mfMF");
    if (gender == 'M'|| gender =='m')
        bmr = maleBmr (weight,height,age);
    else
        bmr = femaleBmr (weight,height,age);

    activity = printBmrmenu ();
    cout << "You Should be consuming " << (activity * bmr) << "Every Day" << endl;

}
float Genie::maleBmr (int w, int h, int a)
{
    float bmr = (655 + ( 4.35 * w) + ( 4.7 * h) - ( 4.7 * a));
    return bmr;
}
float Genie::femaleBmr(int w, int h, int a)
{
    float bmr = (66 + ( 6.23 * w) + ( 12.7 * h) - ( 6.8 * a));
    return bmr;
}
float Genie::printBmrmenu ()
{
    float activity;
    int mainchoice;
        cout << "How active is your daily lifestyle?\n"
            << "1. If you are sedentary (little or no exercise)\n"
            << "2. If you are lightly active (light exercise/sports 1-3 days/week)\n"
            << "3. If you are moderatetely active (moderate exercise/sports 3-5 days/week)\n"
            << "4. If you are very active (hard exercise/sports 6-7 days a week)\n"\
            << "5. If you are extra active (very hard exercise/sports & physical job or 2x training)\n"
            << endl;
        mainchoice = reader.readInt(1,5);
        switch (mainchoice)
        {
            case 1:
                activity = 1.2;
            break;
            case 2:
                activity = 1.375;
            break;
            case 3:
                activity = 1.55;
            break;
            case 4:
                activity = 1.725;
            break;
            case 5:
                activity = 1.9;
            break;
        }
        return activity;
}


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
#include "Genie.h"

#include <ctime>
//#include <iostream>
//#include "CinReader.h"
//#include <string>

using namespace std;

int main()
{
    srand(time(0));

    cout << "Wow you found a Magical Genie Lamp\n"
    << "You rub the lamp and the Genie appears in a puff of smoke.\n"
    << "\"You have awakened me from my century long slumber\n"
    << "I am yours to command, What would you like to call me?\""
    << endl;
    string genieName = reader.readString();
    Genie* genie;
    genie = new Genie;

    genie->name = genieName;
    bool quit = 0;
    while (quit == 0)
    {
        cout << "My name is " << genieName << " and I am here to serve you." << endl;
        int mainchoice;
        cout << "What would you like to do?\n"
            << "1. Answer My Yes/No question.\n"
            << "2. Tell me how my day will go.\n"
            << "3. Tell me what my daily calorie intake should be."
            << "4. Quit.\n"
            << endl;
        mainchoice = reader.readInt(1,4);
        switch (mainchoice)
        {
            case 1:
                genie->giveFortune();
            break;
            case 2:
                genie->affirmLife ();
            break;
            case 3:
                genie->calorie ();
            break;
            case 4:
                quit = 1;
            break;
        }
    }


    delete genie;
    return 0;
}

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
#pragma once

#include <iostream>
#include <string>
#include "CinReader.h"
using namespace std;

CinReader reader;

class Genie
{
    public:
        string name;

        void Genie::affirmLife ();

        string Genie::giveFortune ();

        void Genie::calorie ();



    private:
        float Genie::maleBmr (int w, int h, int a);

        float Genie::femaleBmr(int w, int h, int a);

        float Genie::printBmrmenu ();

};
Last edited on
BumpZ I have been working on this for a while and still cant find my issue. it all looks legit to me.
Don't give abridged error messages. Post the whole error.

Specifically this one:

obj\Debug\Genie.o:C:\MinGW\Bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_factes.tcc ...... line 2497 first defined here


This hints something is multiply defined, but you don't say what is being multiply defined.
the ..... are spaces. that is the entire error message
o_O

That is very strange. Let me take a closer look.
what is locale_factes.tcc?
ok i found the file in std but not understanding why my code violates this file.
NEW Help. It has something to do with my cinreader. Its says i am defining it twice. i have updated my code to what i am currently working with.
Ah, you are including it once in Genie.cpp and once in your main.cpp file. Apparently it does not have header guards. Go and add them if you can.
i removed all the cinreader includes except the one in genie.h still same code. not sure where else i have it at
AHHH im going crazy... i keep compiling and running with hopes that i will get a new result. it doesnt work.
The true error code points to something in main.cpp

C:/Users/Main/Documents/C++/ganie2/main.cpp:(.bss+0x0): multiple definition of `reader'
You redefined reader somewhere, but you knew that.

-Albatross
It is defined in Genie.h and everywhere else it is being used from Genie.h
Last edited on
Then you might have a double-include somewhere.

-Albatross
SOLVED!!! Thankyou everyone.. here was my problem.
I have reader used in my Genie.cpp and Main.cpp file. The instances of reader have to be different. I removed theCinReader reader from Genie.h

then added
CinReader read
to Genie.cpp

and i added
CinReader reader
to Main.cpp

i changed everything needed to call my functions and finally it worked perfectly.
i think my includes are fine.
Last edited on
Topic archived. No new replies allowed.