passing a variable into a function
This is what I would like to do:
//----Main Cpp file-----
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
|
int main()
{
bool myBool = true;
if (someCondition == NULL)
{
myBool = false;
}
//create instance of another class ClassA
ClassA classA(someMap, reportFile);
int someInt = classA.startClassA();
}
//....header file for - ClassA.h
#include <fstream>
......
class ClassA
{
int aBC;
int aBCD;
std::map<std::string, someObj*>&someMap;
std::ofstream& reportFile;
public:
ClassA(std::map<std::string, someObj*>&someMap, std::ofstream& reportFile);
int startClassA();
int someFunc();
);
#endif
//....ClassA.cpp file
#include ClassA.h
...
ClassA::ClassA(map<string, someObj*>&someMap, ofstream& file): reportFile(file),
someMapA(someMap), someNo(0)
{
}
int ClassA::startClassA()
{
....
....
if (myBool = false)
{
}
return 0;
}
|
How do I pass the value of myBool in my main Cpp file into the function startClassA ?
Thanks...
Add a boolean parameter to the method/function and pass a boolean argument to it when it is called.
Here's a simplification:
1 2 3 4 5 6
|
void f( bool b ) {
if( b ) { /*...*/ }
}
//...
bool bb = true;
f( bb );
|
Last edited on
Thanks that works.....
So simple - yet it had me perplexed for some bit of time
Topic archived. No new replies allowed.