Variables in void functions working with other void functions?

Is there a way to make variables used in a void function work in another void function.

for example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  class someClass
{
public:
void someNumber()
{
a = 7
x = 5
}
void someMath()
{
someClass obj2;
obj2.someNumber();
cout << a+x << endl;
}
private:
int a;
int x;
};

int main
{
someClass obj;
obj.someMath();
}


I'm trying to get the someMath function to give the value of a (7) + x (5).
but whenever it adds these two variables, it never works correctly.
i know i can just simply put the vars in main and add them in main but i'm working on a project that relies on the use of variables that were created by other functions in new functions.
obj2 has the variables a and x so insted of cout<<a+x try cout<<Obj2.a+Obj2.x also on line 6 and 7 put semicolon
Why create obj2? You can get rid of lines
1
2
someClass obj2;
obj2.someNumber();
and replace them with just someNumber();
i thought u needed an obj to call a function?
well thinking about it... int the project im working on someClass is actually in a separate header file.
someMath and someNumber are both member functions of someClass. A member function acts as though it is the object itself performing the action. So when you call obj.someMath(); inside that someMath function it will act as obj. It's kind of hard to reason about with such obscure names, consider

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Dog
{
public: 
    Dog() { isClean = false; }
    void lickSelf()
    {
        isClean = true;
    }
    void printIsClean()
    {
        cout << isClean << "\n";
    }
private:
    bool isClean;
};

int main()
{
    Dog Rover;
    Rover.printIsClean();
    Rover.lickSelf();
    Rover.printIsClean();
}

Here we have a dog that starts off dirty, licks itself, and ends up clean. Having the class in a separate header is irrelevant to this situation.
so what if void lickSelf() relies also on user input?
for instance (but a different example, going back to my example)

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
 class someClass
{
public:
void someNumber()
{
cout << "value of a is: ";
cin >> a;
cout << endl;
cout << "value of x is: ";
cin >> x;
}
void someMath()
{

cout << a+x << endl;
}
private:
int a;
int x;
};

int main
{
someClass obj;
obj.someNumber();
obj.someMath();
}


if you enter 5 for a and 7 for x would a and x keep their values?
would a and x keep their values?
Absolutely. In your original post you were creating an entire new object (obj2) giving it some values and then throwing obj2 away, that's why the original objects values never changed.
oooooh. wow...
im not really sure what im doing wrong here.
(this is a very small version of what im working on)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include <iostream>
#include "Choosing Race.h"
#include "Choosing Class.h"
#include "HuF.h"


int main()
{

    chooseRace a;
    return 0;
}

//this is Choosing Race.h file:

#ifndef __combat_test__Choosing_Race__
#define __combat_test__Choosing_Race__

#include <iostream>
#include "HuF.h"
#include "Choosing Class.h"
using namespace std;
class chooseRace
{
public:
    chooseRace()
    {
        std::cout << "list of races:" <<endl;
        std::cout << "1.) Human" << endl;
        std::cout << "what is your race?: ";
        std::cin >> chooser;
        
        std::cout << endl;
        
        if (chooser == '1')
        {
            Choosing_Class a;
        }
    }
private:
    char chooser;
};
#endif


//this is Choosing Class.h file:


#ifndef __combat_test__Choosing_Class__
#define __combat_test__Choosing_Class__

#include <iostream>
#include "HuF.h"
using namespace std;
class Chooseing_Class
{
public:
    Chooseing_Class()
    {
        char choosec;
        char echooser;
        char echoosec;
        
        std::cout << "list of classes:" << endl;
        std::cout << "1.) Fighter" << endl;
if (choosec == '1')
        {
            HuF fighterObj;
            fighterObj.HuFS();
            
            
            std::cout << "Build your enemy: List of races:" <<endl;
            std::cout << "1.) Human" << endl;
  if (echooser == '1')
                //enemy class choose and stats
            {
                std::cout << "list of classes:" << endl;
                std::cout << "1.) Fighter" << endl;
 if (echoosec == '1')
                {
                    
                    fighterObj.EHuF();
         
                }
}
}
};

//this is HuF.h file, this is where all of the stats are created.

#ifndef __combat_test__HuF__
#define __combat_test__HuF__

#include <iostream>
#include <cmath>
using namespace std;
class HuF
{
public:
    //all you and enemy fighter classes with stats
    
    // Human -> All Fighter Classes stats

    
    void HuFS()
    {
        
        std::cout << "what is your level?: ";
        std::cin >> ylvl;
        ylvl--;
        constant = (1+HuF::HumanFG[0][0]);
        i = pow(constant, ylvl);
        yhp = i * HumanFS[0];
        
        constant = (1+HumanFG[0][1]);
        i = pow(constant, ylvl);
        ymp = i * HumanFS[1];
        
        constant = (1+HuF::HumanFG[0][2]);
        i = pow(constant, ylvl);
        ypatk = i * HumanFS[2];
        
        constant = (1+HumanFG[0][3]);
        i = pow(constant, ylvl);
        ymatk = i * HumanFS[3];
        
        constant = (1+HumanFG[0][4]);
        i = pow(constant, ylvl);
        yratk = i * HumanFS[4];
        
        constant = (1+HumanFG[0][5]);
        i = pow(constant, ylvl);
        ypdef = i * HumanFS[5];
        
        constant = (1+HumanFG[0][6]);
        i = pow(constant, ylvl);
        ymdef = i * HumanFS[6];
        
        constant = (1+HumanFG[0][7]);
        i = pow(constant, ylvl);
        yrdef = i * HumanFS[7];
        
        constant = (1+HumanFG[0][8]);
        i = pow(constant, ylvl);
        ydb = i * HumanFS[8];
        
        constant = (1+HumanFG[0][9]);
        i = pow(constant, ylvl);
        yacc = i * HumanFS[9];
        
        constant = (1+HumanFG[0][10]);
        i = pow(constant, ylvl);
        ycr = i * HumanFS[10];
        
        constant = (1+HumanFG[0][11]);
        i = pow(constant, ylvl);
        yas = i * HumanFS[11];
}

void EHuF()
    {
        
        std::cout << "what is your enemies level?: ";
        std::cin >> elvl;
        elvl--;
        constant = (1+HumanFG[0][0]);
        i = pow(constant, elvl);
        ehp = i * HumanFS[0];
        
        constant = (1+HumanFG[0][1]);
        i = pow(constant, elvl);
        emp = i * HumanFS[1];
        
        constant = (1+HumanFG[0][2]);
        i = pow(constant, elvl);
        epatk = i * HumanFS[2];
        
        constant = (1+HumanFG[0][3]);
        i = pow(constant, elvl);
        ematk = i * HumanFS[3];
        
        constant = (1+HumanFG[0][4]);
        i = pow(constant, elvl);
        eratk = i * HumanFS[4];
        
        constant = (1+HumanFG[0][5]);
        i = pow(constant, elvl);
        epdef = i * HumanFS[5];
        
        constant = (1+HumanFG[0][6]);
        i = pow(constant, elvl);
        emdef = i * HumanFS[6];
        
        constant = (1+HumanFG[0][7]);
        i = pow(constant, elvl);
        erdef = i * HumanFS[7];
        
        constant = (1+HumanFG[0][8]);
        i = pow(constant, elvl);
        edb = i * HumanFS[8];
        
        constant = (1+HumanFG[0][9]);
        i = pow(constant, elvl);
        eacc = i * HumanFS[9];
        
        constant = (1+HumanFG[0][10]);
        i = pow(constant, elvl);
        ecr = i * HumanFS[10];
        
        constant = (1+HumanFG[0][11]);
        i = pow(constant, elvl);
        eas = i * HumanFS[11];

figterObj.FightStart();

}

    void FightStart()
    {
        ypdamt = ypatk;
        ypdamb = epdef;
        epdamt = epatk;
        epdamb = ypdef;
        int ypdamf = ypdamt/ypdamb;
        int epdamf = epdamt/epdamb;
        cout << ypdamf << endl;
        cout << epdamf << endl;
    }


basically whenever i send ypdamf and epdamf to cout, i get 0 for both.
closed account (j3Rz8vqX)
My assumption is that you are printing data from your class "Choosing_Class" when not in scope.

Choosing_Class is declare on line 37, and is only defined within that scope; in the if condition scope.

Some tutorials:
http://www.cplusplus.com/doc/tutorial/classes/

Is there a way to make variables used in a void function work in another void function.
If both of the variables are available to the class, I don't see why they wouldn't be able to call each other...

Example:
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
#include <iostream>
using namespace std;
class myClass{
private:
    int x, y, z;
public:
    myClass(){x=y=z=0;}
    int prompt(const char &ch)
    {
        int value;
        while(cout<<"Enter "<<ch<<" value: " && !(cin>>value))
        {
            cin.clear();
            cin.ignore(1000,'\n');
            cout<<"Invalid entry, try again...\n\n";
        }
        cin.ignore(1000,'\n');
        return value;
    }
    void set()
    {
        x = prompt('X');
        y = prompt('Y');
        z = prompt('Z');
    }
    void print()
    {
        cout<<"X|Y|Z\n"<<x<<'|'<<y<<'|'<<z<<'\n';
    }
};

int main()
{
    myClass T;
    T.set();
    T.print();
    return 0;
}
Enter X value: 8
Enter Y value: 5
Enter Z value: 6
X|Y|Z
8|5|6

Process returned 0 (0x0)   execution time : 4.581 s
Press any key to continue.

In the above, set() calls three instances of prompt().
lets see... so

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//starting with main.cpp, keep in mind that all of the .h's in the project dont have a corresponding .cpp

#include <iostream>
#include "Choosing Race.h"
#include "Choosing Class.h"
#include "HuF.h"


int main()
{

    chooseRace a;
    return 0;
}


//choosing race.h
#ifndef __combat_test__Choosing_Race__
#define __combat_test__Choosing_Race__

#include <iostream>
#include "HuF.h"
#include "Choosing Class.h"
using namespace std;
class chooseRace
{
public:
    chooseRace()
    {
        std::cout << "list of races:" <<endl;
        std::cout << "1.) Human" << endl;
        std::cout << "what is your race?: ";
        std::cin >> chooser;
        
        std::cout << endl;
        
        if (chooser == '1')
        {
            Chooseing_Class a;
        }
    }
private:
    char chooser;
    
 //choosing class.h

#ifndef __combat_test__Choosing_Class__
#define __combat_test__Choosing_Class__

#include <iostream>
#include "HuF.h"
using namespace std;
class Chooseing_Class
{
public:
    Chooseing_Class()
    {
        char choosec;
        char echooser;
        char echoosec;
        
        std::cout << "list of classes:" << endl;
        std::cout << "1.) Fighter" << endl;
        std::cout << "what is your class (type n for next 10)?: ";
        std::cin >> choosec;
        if (choosec == '1')
        {


            HuF fighterObj;
            fighterObj.HuFS(); //HuFS() is another void created in HuF.h which will come next.
            
            
            std::cout << "Build your enemy: List of races:" <<endl;
            std::cout << "1.) Human" << endl;
            std::cout << "what is your enemies race?: ";
            std::cin >> echooser;
            if (echooser == '1')
   
};

//HuF.h

#ifndef __combat_test__HuF__
#define __combat_test__HuF__

#include <iostream>
#include <cmath>
using namespace std;
class HuF
{
public:
    //all you and enemy fighter classes with stats
    
    // Human -> All Fighter Classes stats

    
    void HuFS()
    {
        
        std::cout << "what is your level?: ";
        std::cin >> ylvl;
        ylvl--;
        constant = (1+HuF::HumanFG[0][0]);
        i = pow(constant, ylvl);
        yhp = i * HumanFS[0];
        
        constant = (1+HumanFG[0][1]);
        i = pow(constant, ylvl);
        ymp = i * HumanFS[1];
        
        constant = (1+HuF::HumanFG[0][2]);
        i = pow(constant, ylvl);
        ypatk = i * HumanFS[2];
        
        constant = (1+HumanFG[0][3]);
        i = pow(constant, ylvl);
        ymatk = i * HumanFS[3];
        
        constant = (1+HumanFG[0][4]);
        i = pow(constant, ylvl);
        yratk = i * HumanFS[4];
        
        constant = (1+HumanFG[0][5]);
        i = pow(constant, ylvl);
        ypdef = i * HumanFS[5];
        
        constant = (1+HumanFG[0][6]);
        i = pow(constant, ylvl);
        ymdef = i * HumanFS[6];
        
        constant = (1+HumanFG[0][7]);
        i = pow(constant, ylvl);
        yrdef = i * HumanFS[7];
        
        constant = (1+HumanFG[0][8]);
        i = pow(constant, ylvl);
        ydb = i * HumanFS[8];
        
        constant = (1+HumanFG[0][9]);
        i = pow(constant, ylvl);
        yacc = i * HumanFS[9];
        
        constant = (1+HumanFG[0][10]);
        i = pow(constant, ylvl);
        ycr = i * HumanFS[10];
        
        constant = (1+HumanFG[0][11]);
        i = pow(constant, ylvl);
        yas = i * HumanFS[11];
}

 void EHuF()
    {
        
        std::cout << "what is your enemies level?: ";
        std::cin >> elvl;
        elvl--;
        constant = (1+HumanFG[0][0]);
        i = pow(constant, elvl);
        ehp = i * HumanFS[0];
        
        constant = (1+HumanFG[0][1]);
        i = pow(constant, elvl);
        emp = i * HumanFS[1];
        
        constant = (1+HumanFG[0][2]);
        i = pow(constant, elvl);
        epatk = i * HumanFS[2];
        
        constant = (1+HumanFG[0][3]);
        i = pow(constant, elvl);
        ematk = i * HumanFS[3];
        
        constant = (1+HumanFG[0][4]);
        i = pow(constant, elvl);
        eratk = i * HumanFS[4];
        
        constant = (1+HumanFG[0][5]);
        i = pow(constant, elvl);
        epdef = i * HumanFS[5];
        
        constant = (1+HumanFG[0][6]);
        i = pow(constant, elvl);
        emdef = i * HumanFS[6];
        
        constant = (1+HumanFG[0][7]);
        i = pow(constant, elvl);
        erdef = i * HumanFS[7];
        
        constant = (1+HumanFG[0][8]);
        i = pow(constant, elvl);
        edb = i * HumanFS[8];
        
        constant = (1+HumanFG[0][9]);
        i = pow(constant, elvl);
        eacc = i * HumanFS[9];
        
        constant = (1+HumanFG[0][10]);
        i = pow(constant, elvl);
        ecr = i * HumanFS[10];
        
        constant = (1+HumanFG[0][11]);
        i = pow(constant, elvl);
        eas = i * HumanFS[11];

fighterObj.FightStart();
}


    void FightStart()
    {
        ypdamt = ypatk;
        ypdamb = epdef;
        epdamt = epatk;
        epdamb = ypdef;
        int ypdamf = ypdamt/ypdamb;
        int epdamf = epdamt/epdamb;
        cout << ypdamf << endl;
        cout << epdamf << endl;
    }

    private:
//dont mind the comments on this array, they were simply to keep myself organized.
 double HumanFG[10][12] =
         //HP   MP     PA   MA   RA   PD    MD    RD    DB    ACC    CR     AS
    {   {.0701,.05997,.105,.092,.095,.061,.0590,.0490,.0571,.05107,.04512,.0177}, //F 0
        {.0741,.06021,.110,.094,.096,.075,.0670,.0540,.0602,.05137,.04551,.0175}, //SS 1
        {.0821,.06532,.125,.095,.097,.094,.0820,.0730,.0751,.05219,.04621,.0218}, //P 2
        {.0831,.06604,.120,.082,.093,.101,.0935,.0805,.0761,.05155,.04561,.0182}, //W 3
        {.0732,.06010,.124,.092,.095,.064,.0620,.0520,.0582,.05313,.05132,.0193}, //DW 4
        {.0781,.07204,.132,.093,.095,.072,.0680,.0550,.0601,.05352,.05324,.0224}, //GU 5
        {.0775,.06891,.141,.093,.095,.068,.0661,.0545,.0631,.05521,.05435,.0241}, //GL 6
        {.0751,.06013,.127,.093,.098,.067,.0611,.0621,.0573,.05120,.04822,.0179}, //2H 7
        {.0781,.06061,.131,.094,.098,.071,.0632,.0630,.0577,.05133,.05102,.0187}, //D 8
        {.0773,.06121,.137,.095,.099,.067,.0622,.0613,.0575,.05127,.05210,.0192}}; //R 9


int HumanFS[12] =
    {137,58,6,4,5,72,45,66,19,25,12,2};

    char chooser;
    char choosec;
    char echooser;
    char echoosec;


    int epdamt;
    int ypdamb;
    int epdamb;
    int ypdamt;

    int yhp;
    int ymp;
    int ypatk;
    int ypdef;
    int yratk;
    int yrdef;
    int ymatk;
    int ymdef;
    int ydb;
    int yacc;
    int ycr;
    int yas;

    int ehp;
    int emp;
    int epatk;
    int epdef;
    int eratk;
    int erdef;
    int ematk;
    int emdef;
    int ylvl;
    int edb;
    int eacc;
    int ecr;
    int eas;
    int x;
    double constant;
    double i;
    char chooseer;
    char chooseec;
    int elvl;
    int y;


this shows:


list of races:
1.) Human
what is your race?: 1

list of classes:
1.) Fighter
what is your class (type n for next 10)?: 1
what is your level?: 40
Build your enemy: List of races:
1.) Human
what is your enemies race?: 1
list of classes:
1.) Fighter
what is your enemies class (type n for next 10)?: 1
what is your enemies level?: 40
(lldb)

lldb just started happening but going back to my code. after entering in 40 for (what is the variable) ylvl, i thinks ylvl = 1606406464
and after entering in 40 for what is elvl, the compiler thinks it is 0 which gives me the lldb because later when fightStart() is called, the math has a 0 in one of the denominators. :<
i also tried indexing the stats (yhp ymp ypatk etc and ehp emp epatk etc) in an array like this:

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
private:
int yHFSA [12];
int eHFSA [12];
public:
    void HuFS()
    {
        
        std::cout << "what is your level?: ";
        std::cin >> ylvl;
        ylvl--;
        constant = (1+HuF::HumanFG[0][0]);
        i = pow(constant, ylvl);
        yhp = i * HumanFS[0];
        
        constant = (1+HumanFG[0][1]);
        i = pow(constant, ylvl);
        ymp = i * HumanFS[1];
        
        constant = (1+HuF::HumanFG[0][2]);
        i = pow(constant, ylvl);
        ypatk = i * HumanFS[2];
        
        constant = (1+HumanFG[0][3]);
        i = pow(constant, ylvl);
        ymatk = i * HumanFS[3];
        
        constant = (1+HumanFG[0][4]);
        i = pow(constant, ylvl);
        yratk = i * HumanFS[4];
        
        constant = (1+HumanFG[0][5]);
        i = pow(constant, ylvl);
        ypdef = i * HumanFS[5];
        
        constant = (1+HumanFG[0][6]);
        i = pow(constant, ylvl);
        ymdef = i * HumanFS[6];
        
        constant = (1+HumanFG[0][7]);
        i = pow(constant, ylvl);
        yrdef = i * HumanFS[7];
        
        constant = (1+HumanFG[0][8]);
        i = pow(constant, ylvl);
        ydb = i * HumanFS[8];
        
        constant = (1+HumanFG[0][9]);
        i = pow(constant, ylvl);
        yacc = i * HumanFS[9];
        
        constant = (1+HumanFG[0][10]);
        i = pow(constant, ylvl);
        ycr = i * HumanFS[10];
        
        constant = (1+HumanFG[0][11]);
        i = pow(constant, ylvl);
        yas = i * HumanFS[11];

yHSFA [0] = {yhp};
yHSFA [1] = {ymp};
//etc etc etc etc... same goes for the enemy stats.
}


but this didnt do anything either because it still thinks yhp and ymp and all of those are different numbers outside of that specific void function
its almost like i have to create both the stats without having user input for enemy. which dosnt really seem... correct.
bump?
any one xD?
Why are there constant values for the HumanFGs, and why would you have a class with
1
2
3
4
5
6
7
8
9
10
11
12
class math
{
public:
void doMath()
{
cout << variable1 + variable 2;
}
private:
int variable1;
int variable2;

}



then,


1
2
math add;
add.doMath()


How can add have variable1 and variable2 if they are private?
also, could you put

1
2
3
4
5
6
7
8
9
10
11
class math
{
int variable1;
int variable2;
public:
void doMath()
{
cout << variable1 + variable2;
}

}
Last edited on
1.) Why are there constant values for the HumanFGs, and why would you have a class with

class math
{
public:
void doMath()
{
cout << variable1 + variable 2;
}
private:
int variable1;
int variable2;

}

there are constants because if you look at the formulas, its the growthrate formula which im using to calculate stats for each character, and there fore, each formula needs a specific stat. i have a class like that because it needs to be called at a specific time. which is after one has chosen both their race and their class.

2.) how can add have variable1 and 2 if they are private?

because void add is in the same class, and therefore i can use it in that class and in that void function.
closed account (j3Rz8vqX)
but this didnt do anything either because it still thinks yhp and ymp and all of those are different numbers outside of that specific void function
Which they are.

Your classes are being declared within the scope of if's and functions; their data will not persist outside of those scopes.

A constructor, creating local data within itself will only be available to the constructor method.

As for your extensively long function, an alternative to your two functions; recursive:
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
void HuFS()
{
    int *player[] = {&yhp,&ymp,&ypatk,&ymatk,&yratk,&ypdef,&ymdef,&yrdef,&ydb,&yacc,&ycr,&yas};
    std::cout << "what is your level?: ";
    std::cin >> ylvl;
    --ylvl;
    for(int counter=0;counter<12;++counter)
    {
        constant = (1+HuF::HumanFG[0][counter]);
        i = pow(constant, ylvl);
        *player[counter] = i * HumanFS[counter];
    }
}
void EHuF()
{
    int *enemy[] = {&ehp,&emp,&epatk,&ematk,&eratk,&epdef,&emdef,&erdef,&edb,&eacc,&ecr,&eas};
    std::cout << "what is your enemies level?: ";
    std::cin >> elvl;
    --elvl;
    for(int counter=0;counter<12;++counter)
    {
        constant = (1+HuF::HumanFG[0][counter]);
        i = pow(constant, elvl);
        *enemy[counter] = i * HumanFS[counter];
    }
}


It isn't that we are avoiding your main question, the point is that what you are attempting isn't going to work.
Chooseing_Class a;
needs to be declared outside of that constructor to have any significance beyond the completion of that constructor method.

Same applies for
HuF fighterObj;
as soon as you're finished with the chooseing class constructor, HuF will be destroyed. And Chooseing class object will be destroyed when choosing race constructor ends.

Lines 39(choosing_class), 70(HuF) are local objects to those specific methods only.

Edit: Minor fixes.
Last edited on
Topic archived. No new replies allowed.