HELP PLEASE. DYnamic variable

solved
Last edited on
You'll need a pointer for this. Allocate the memory for it during the calculation, and then delete it when you have no further use of the data.
Austin j


where ? where in the class that was my question. where do i declare the pointer, in public, in private. no one knows ?
Not in the class. I think they want you to manually allocate the variable within main, and then do things, and then delete it again, like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//...

class Area {
    // ...
};

int main() {
    Area *a = new Area;

    // do stuff with a

    delete a;
    return 0;
}
solved
Last edited on
I understand that what he is trying to do is make us access the private variable through the dynamic variable. correct ?


No.
Dynamic or not, you won't be able to access a private variable.

It looks like you are required to write Getters and Setters maybe?
Last edited on
mutexe

Ahh.. we haven't learned those though. I can write a public function and access the variables and compute one half of the area like he asked us to that would not be an issue, but... i wonder what would be the use of the dynamic variable, why did he ask us to declare one.

again I suck at pointers and dynamic variables so my understanding to their use is limited.
looks like you will need:

1
2
3
void SetArea(float area);
void Setunits(string units);
float CalculateHalfArea(void);

OR, just

float CalculateHalfArea(float area, string units);

as your public interface (depends on if you want to save your units and area inside your object, which is looks like you do).
Last edited on
okay so public functions, got ya.. what about the dynamic what is the use of it...
NT3 gave you a could example above.

as to what use it is using a dynamic variable in this context.. none whatsoever.
Topic archived. No new replies allowed.