d****p 发帖数: 685 | 1 Is the following code right:
void foo()
{
struct MyFoo
{
int a;
int b;
};
MyFoo myFoo;
// do stuff
}
How about this one:
void foo()
{
struct MyFoo
{
int a;
int b;
};
std::vector myFooList;
// do stuff
} |
a****o 发帖数: 686 | |
d****p 发帖数: 685 | 3 正解。
我想说的时我和同事关于一个coding的分歧。
我喜欢用boost::tuple来表示一些临时的数据类型:经常我们在函数中局部定义。我的
同事认为用一个结构更可读。这点说他是对的。对比
typedef boost::tuple Position3D;
以及
struct Position3D
{
int x;
int y;
int z;
};
std::vector vertices;
//...
for (std::vector::iterator vertexItr = vertices.begin();
vertexItr != vertices.end(); ++vertexItr)
{
// vertexItr->x = 0; // local struct more readable
// vertexItr->first = 0; // boost::tuple
}
显然局部结构的代码更可读。
不过坏处就是无法作为模板参数。
【在 a****o 的大作中提到】 : template不能用local type吗?
|
t****t 发帖数: 6806 | 4 this restriction has been relieved in c++0x. gcc 4.5 supports it now.
【在 d****p 的大作中提到】 : 正解。 : 我想说的时我和同事关于一个coding的分歧。 : 我喜欢用boost::tuple来表示一些临时的数据类型:经常我们在函数中局部定义。我的 : 同事认为用一个结构更可读。这点说他是对的。对比 : typedef boost::tuple Position3D; : 以及 : struct Position3D : { : int x; : int y;
|
d****p 发帖数: 685 | 5 Oh, cool. I thought only Visual Studio supports it now.
I am very passionate about c++0x since it will make this language more
design friendly. I look forward to seeing things like auto and partial
template specialization.
【在 t****t 的大作中提到】 : this restriction has been relieved in c++0x. gcc 4.5 supports it now.
|
t****t 发帖数: 6806 | 6 isn't partial specialization from c++98?
or you meant variadic templates?
【在 d****p 的大作中提到】 : Oh, cool. I thought only Visual Studio supports it now. : I am very passionate about c++0x since it will make this language more : design friendly. I look forward to seeing things like auto and partial : template specialization.
|
d****p 发帖数: 685 | 7 I meant partial specialization. I thought it was not in standard since
several compilers I use don't support it.
Definitely you are right that it is already in standard.
【在 t****t 的大作中提到】 : isn't partial specialization from c++98? : or you meant variadic templates?
|