由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ template
相关主题
C++ Q42: (C22)C++定义数组长度可以写成int a[n]吗?
c++ 数组问题我也发个工作
问一个C++问题:default parameter and overriding/inheritanc网上c sample question的一堆错误
C++ online Test 又一题error of compiling C# in visual studio 2013 win 7
C++: Q75 copy constructor 问什么用 const reference?怎么才能避免每次都写using namespace std
Mathworks is hiring! job #10319 - C++ Developer – Compile请问这句话是说要initial phone interview 吗?
Compiler/C++ position @Mathworksvirtual table存在memory的哪块啊?
一个电面Bloomberg(financial software developer)第一轮面试
相关话题的讨论汇总
话题: template话题: c++话题: time话题: buffer话题: compiling
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
1. Is the C++ template parameters decided at the compiling time or running
time?
2. How do you know the C++ template parameters are decided at the compiling
time or running time?
1 is simple. But how to answer 2? Thanks a ton.
i**********e
发帖数: 1145
2
2. You can run some simple tests. By increasing the number of different
types being called to a function of generic type, you should notice the
binary file being larger, due to extra code being generated by the compiler
(for each of the type used). Haven't verified this myself yet, so if I'm
wrong please feel free to correct.
s******n
发帖数: 3946
3
编译成汇编,每个method都有独立的signature
h*****f
发帖数: 248
4
1. Compile time because template initialization is done during the compile
time and the initialization is based on the "known" template parameter(s)
during the compile time.
2. A way to prove:
#include
#include
template class Buffer {
char internal[max];
public:
void printSize() {
printf("buffer size=%lu\n", sizeof(internal));
}
};
int main() {
Buffer<512> my512;
my512.printSize();
size_t v;
std::cin >> v;
printf("my input=%lu\n", v);
/* Compilation error because tmeplate is generated in the compilation time,
and so a template cannot take a runtime value as the parameter
Buffer myInput;
myInput.printSize();
*/
return 0;
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
Bloomberg(financial software developer)第一轮面试C++: Q75 copy constructor 问什么用 const reference?
Q in C/C++Mathworks is hiring! job #10319 - C++ Developer – Compile
求救:第一次电话面试Compiler/C++ position @Mathworks
bloomberg电面2,攒rp求bless (给据了 :()一个电面
C++ Q42: (C22)C++定义数组长度可以写成int a[n]吗?
c++ 数组问题我也发个工作
问一个C++问题:default parameter and overriding/inheritanc网上c sample question的一堆错误
C++ online Test 又一题error of compiling C# in visual studio 2013 win 7
相关话题的讨论汇总
话题: template话题: c++话题: time话题: buffer话题: compiling