由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ Template Question
相关主题
recursive template?C++ online Test 又一题 (转载)
typedef这个function pointer最后的那个int是什么意思?
一道面试怪题C++. (转载)C or C++ test
C++ template question请问const myClass &src 和myClass const &src有什么区别?
[合集] 又被羞辱了一把... (转载)一个partial specialization的问题
关于C++ STL编译的疑问class D:public B;
请问如何把初始化一个const 的vector (or array) in a class?C++ memcpy declaration use restrict keyword?
基础问题:在header里面define function[合集] Interview Question
相关话题的讨论汇总
话题: vector话题: c++话题: datatyp话题: template话题: question
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
[合集] Interview Question[合集] 又被羞辱了一把... (转载)
pointer to function关于C++ STL编译的疑问
int (*b)[2]; 是什么意思?请问如何把初始化一个const 的vector (or array) in a class?
address of an array基础问题:在header里面define function
recursive template?C++ online Test 又一题 (转载)
typedef这个function pointer最后的那个int是什么意思?
一道面试怪题C++. (转载)C or C++ test
C++ template question请问const myClass &src 和myClass const &src有什么区别?
相关话题的讨论汇总
话题: vector话题: c++话题: datatyp话题: template话题: question