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. |
|