F
firegun9
Hello all,
After looking for the solution for a while in the group, I know this is
not possible in C++. So I just say my problme here.
The input file is:
dev1 1 1
dev2 0 0 0 6
There is a base class "Base" and two derivated classes "dev1" and
"dev2".
The best way of my code is like:
Read_line_from_file(char* arg1, char* arg2, char* arg3);
Base* p_base = new arg1(arg2, arg3);
If I could have a dynamic variable, the second statement above can new
any type of future derivative class without changing the codes here.
For example, if I have a new class dev3, I just add a line of "dev3 5 5
5" into the text file, then the code will new a "dev3" object.
Isn't it so cool?
However, I can't do that.
Any better idea about this?
After looking for the solution for a while in the group, I know this is
not possible in C++. So I just say my problme here.
The input file is:
dev1 1 1
dev2 0 0 0 6
There is a base class "Base" and two derivated classes "dev1" and
"dev2".
The best way of my code is like:
Read_line_from_file(char* arg1, char* arg2, char* arg3);
Base* p_base = new arg1(arg2, arg3);
If I could have a dynamic variable, the second statement above can new
any type of future derivative class without changing the codes here.
For example, if I have a new class dev3, I just add a line of "dev3 5 5
5" into the text file, then the code will new a "dev3" object.
Isn't it so cool?
However, I can't do that.
Any better idea about this?