Hello agill,
It looks like you my need to read this first"
http://www.cplusplus.com/doc/tutorial/classes/
Follower at some time by:
http://www.cplusplus.com/doc/tutorial/templates/
The first thing you will have to do is create an object or instance of the class in main. Based on what I see it might be:
tree_treeData treeData;
or any other name you would like. Then in the program you would call a member function of the class as
treeDats.info;
.
You will have to use public member functions of the class to access private member variables of the function. There is no way to directly access the private member variables or functions outside the class.
I do not know if it is possible to create a string to call a function or not, but it sounds like fun to give it a try.
In the first bit of code it looks:
treeData=treeForm();
is calling a non class function that returns a value or did you mean to get information from a class?
The class you have shown is not the best way to write the class. Something like this is a better use of the class:
1 2 3 4 5 6 7 8 9 10 11
|
class tree_1111
{
public:
tree_1111() // <--- Default ctor.
tree_1111(std::string str); //<--- Overloaded ctor to set string when defined in main.
std::string GetInfo(); // <--- Used to get the private data.
private:
std::string string info;
};
std::string tree_1111:GetInfo() { return info; }
|
What you have makes the variable "info" public which defeats the point of the class. A struct or simple variable would work just as well.
Thinking about your question I do not believe that using a string to create a variable name for the class will work. I am thinking that it would give a redefinition error of the string name at compile time.
What might work better is to use one object of the class and store that information in a vector or array then change the data before storing the changes in the vector or array.
This each element of the vector or array would contain different data values.
Hope that helps,
Andy