s*****g 发帖数: 5159 | 1 First, thank you for looking into my post, I sincerely appreciate your help.
I have a program that takes one input parameter, that determines the datatyp
e will be used in my program. |
d**e 发帖数: 6098 | 2 if declare p inside "if", it will be out of scope after "if"
how if declare "vector * p"
and then inside "if", p = new vector() or vector() ?
help.
datatyp
【在 s*****g 的大作中提到】 : First, thank you for looking into my post, I sincerely appreciate your help. : I have a program that takes one input parameter, that determines the datatyp : e will be used in my program.
|
z****e 发帖数: 2024 | 3 "vector * p"?
is it a type? |
d**e 发帖数: 6098 | 4 hehe..not quite sure...
i don't have a machine to test right now..
i just try to see if i could do it by new a pointer...
【在 z****e 的大作中提到】 : "vector * p"? : is it a type?
|
s*****g 发帖数: 5159 | 5 I tried and this this does now work.
vector *p must have template defined at declaration.
I am also thinking of using typedef, but I do not know if there is a type fo
r variables's type, like |
t****t 发帖数: 6806 | 6 you simply can't do it that way. C++ type is static, therefore declaring (
new) type according to runtime input is impossible.
you may get around with polymorphism. however vector and vector
does not have a common base, you have to wrap them yourself.
help.
datatyp
【在 s*****g 的大作中提到】 : First, thank you for looking into my post, I sincerely appreciate your help. : I have a program that takes one input parameter, that determines the datatyp : e will be used in my program.
|
s*****g 发帖数: 5159 | 7 I see. Thanks.
I thought of this in my last post.
>
【在 t****t 的大作中提到】 : you simply can't do it that way. C++ type is static, therefore declaring ( : new) type according to runtime input is impossible. : you may get around with polymorphism. however vector and vector : does not have a common base, you have to wrap them yourself. : : help. : datatyp
|