由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 关于C++ STL编译的疑问
相关主题
相关话题的讨论汇总
话题: myclassa话题: vector话题: object话题: 编译
进入Programming版参与讨论
1 (共1页)
i***h
发帖数: 12655
1
突然想到这个(也许是个很蠢的问题,砖头轻拍)
下面的程序:
class myClassA {...}
vector a;
myClassA是我自己定义的一个类, compile时应该单独生成vector这个特例,
那么编译时要有template vector的 definition, 而不仅仅是 declaration,
对吧?
也就是说, 光有library提供的header file interface是不够的?
糊涂了
a**a
发帖数: 416
2
一般来说,模板类的完全定义都在header里,
只不过有些写在类的声明里,有些写在外面。但都在一个文件里。

例,
declaration,

【在 i***h 的大作中提到】
: 突然想到这个(也许是个很蠢的问题,砖头轻拍)
: 下面的程序:
: class myClassA {...}
: vector a;
: myClassA是我自己定义的一个类, compile时应该单独生成vector这个特例,
: 那么编译时要有template vector的 definition, 而不仅仅是 declaration,
: 对吧?
: 也就是说, 光有library提供的header file interface是不够的?
: 糊涂了

P********e
发帖数: 2610
3
你include "vector"的时候,就已经include 了definition了

例,
declaration,

【在 i***h 的大作中提到】
: 突然想到这个(也许是个很蠢的问题,砖头轻拍)
: 下面的程序:
: class myClassA {...}
: vector a;
: myClassA是我自己定义的一个类, compile时应该单独生成vector这个特例,
: 那么编译时要有template vector的 definition, 而不仅仅是 declaration,
: 对吧?
: 也就是说, 光有library提供的header file interface是不够的?
: 糊涂了

i***h
发帖数: 12655
4
那么是不是implementation里保证只有 T 的指针或reference?
否则每次连implementation也要重编译
a**a
发帖数: 416
5
如果你改了T的定义,vector当然就变了。这当然要重新编译。C++的编译是挺耗时间
的。

【在 i***h 的大作中提到】
: 那么是不是implementation里保证只有 T 的指针或reference?
: 否则每次连implementation也要重编译

P********e
发帖数: 2610
6

object

【在 i***h 的大作中提到】
: 那么是不是implementation里保证只有 T 的指针或reference?
: 否则每次连implementation也要重编译

r*********r
发帖数: 3195
7
write a program junk.cpp with ONE line:
#include
and compile it with the -E option,
the output is what the real compiler sees:
g++ -E junk.cpp > tmp.cpp
in the file tmp.cpp, you'll see vector's declaration and definition,
it's about 2,000 lines.
i***h
发帖数: 12655
8
nice. thanks very much.
I did just that and the tmp.cpp has 11712 lines!

【在 r*********r 的大作中提到】
: write a program junk.cpp with ONE line:
: #include
: and compile it with the -E option,
: the output is what the real compiler sees:
: g++ -E junk.cpp > tmp.cpp
: in the file tmp.cpp, you'll see vector's declaration and definition,
: it's about 2,000 lines.

r*********r
发帖数: 3195
9
a lot of them are declaration for the standard C library and
system calls. also, the STL algorithm functions will be included too.
that's why compiling c++ is so much slower than compiling c.
1 (共1页)
进入Programming版参与讨论
相关主题
相关话题的讨论汇总
话题: myclassa话题: vector话题: object话题: 编译