I am writting some code and wish to use a get/set for a class variable. This variable will be used within the main(), and also internally within the class. Here is some syntax to better explain the issue...
Code:int main() { ClassA *test_ptr = 0; if( test_ptr->test_B.getValue() ) { //do something... test_ptr->test_B.setValue(); }Code://within header //skeleton of classA .... ClassB test_B; ....
//CLASSB HEADER
CLASSB CPPCode:ClassB { public: getValue() setValue() private: bool test_value }
My question is in order for test_value to be seen by main should I make test_value a pointer; or can I just make it normal bool value? I am worried about test_value being released/destoryed in operation of the code and I am not really certain if a pointer will resolve that issue. I have looked stuff up but I am still very fuzzy on this!Code:bool ClassB::getValue() { return test_value; } void ClassB::setValue() { if(test_value) test_value = false; else test_value = true; }
Also if its a pointer should I declare it *test_value = true; in the constructor? Thank you for the help in advance.



LinkBack URL
About LinkBacks


