由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Compile issues
相关主题
stl quiz 一问C++ class template specialization question
typedef*** help needed! on MATLAB GUI ***
INIT_WORK从Linux kernel 2.6.20后改了?How to tell gcc stop compiling.
码工试题 (转载)inheritence problem
forward declarationA tech question (转载)
c++ initialize structAn interesting C++ compile error
C array谁来解释一下这个是compiler问题吗?
A C++ compiler related interview question关于Makefile的一个问题
相关话题的讨论汇总
话题: myfoo话题: int话题: struct话题: foo话题: vertexitr
进入Programming版参与讨论
1 (共1页)
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
2
template不能用local type吗?
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?

1 (共1页)
进入Programming版参与讨论
相关主题
关于Makefile的一个问题forward declaration
这句话是为什么呢?c++ initialize struct
spent a lot of time try to compile boostC array
一个qt3在Windows上的问题A C++ compiler related interview question
stl quiz 一问C++ class template specialization question
typedef*** help needed! on MATLAB GUI ***
INIT_WORK从Linux kernel 2.6.20后改了?How to tell gcc stop compiling.
码工试题 (转载)inheritence problem
相关话题的讨论汇总
话题: myfoo话题: int话题: struct话题: foo话题: vertexitr