由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 一道STL面试题
相关主题
C++ Singleton Template - 编译通不过请教一个C++问题
C++ online Test 一题C++问题
问个C++模板定义的问题今早google电面报告
问一道C++ template的面试题C++ template Questions
请教个C++的基础问题C++在vector里找>50的数,怎么找?
帮我看看这两个题目回答问个简单的C++ 函数参数问题
ANY IDEA?大家来讨论一下c++吧
问个构造函数的问题问一个C++ delete 节点的问题
相关话题的讨论汇总
话题: files话题: stl话题: val话题: template话题: temp
进入JobHunting版参与讨论
1 (共1页)
e****9
发帖数: 316
1
刚刚电面被击败。
其中的一个题目是
为什么STL的实现都放在.h文件里?
l******c
发帖数: 2555
2
C++ template

【在 e****9 的大作中提到】
: 刚刚电面被击败。
: 其中的一个题目是
: 为什么STL的实现都放在.h文件里?

j**l
发帖数: 2911
3
类模板的成员函数的定义必须放在头文件中
A***e
发帖数: 130
4
My understanding is, the current coding infrastructure, i.e., high-level language source files --> obj/lib files --> executable files, does not support OO, and in particular, does not support template.
Under this infrastructure, if the implementation of STL were put in the .cpp files, which would be compiled to obj/lib files without any information from the users/caller of these STL class/functions, then the obj/lib files had to link to, and work correctly with the users/callers for all possible

【在 e****9 的大作中提到】
: 刚刚电面被击败。
: 其中的一个题目是
: 为什么STL的实现都放在.h文件里?

a****n
发帖数: 1887
5
模板编译有两种方式inclusion model和 separation model, 放在.h 是inclusion
model, separation model 允许把实现放到cpp,不过非常复杂, 所以绝大多数
template 都是放到h文件中。
模板的编译 首先要生成代码,之后才是真正的编译。如果你的程序找不到定义, 那么
也没有办法做第一次生成。
l********n
发帖数: 54
6
我的理解是这样的:
简单的说,这是由于C++的编译方式和模板的特性导致的。
一个例子:test.cpp, template.cpp, template.h
=====================================
template.h
template
class Temp
{
private:
T _val;
public:
void setVal(T& val);
T& getVal();
};
=====================================
=====================================
template.cpp
#include "template.h"
template
void Temp::setVal(T& val)
{
_val = val;
}
template
T& Temp::getVal()
{
return _val;
l******c
发帖数: 2555
7
correct,
"C++ does not have binary run-time extensibility, templates can't be linked
and distributed as a library. They must be compiled at compile time, and,
therefore, all implementations of a template algorithm must be included in
the header files in their entirety. You can easily see this by analyzing the
STL standard header files".

【在 l********n 的大作中提到】
: 我的理解是这样的:
: 简单的说,这是由于C++的编译方式和模板的特性导致的。
: 一个例子:test.cpp, template.cpp, template.h
: =====================================
: template.h
: template
: class Temp
: {
: private:
: T _val;

1 (共1页)
进入JobHunting版参与讨论
相关主题
问一个C++ delete 节点的问题请教个C++的基础问题
包子求大牛:C++的list iterator实现帮我看看这两个题目回答
真是老了脑子不好使了,struct和class的区别都没答上ANY IDEA?
[合集] 几个面试中碰到的问题问个构造函数的问题
C++ Singleton Template - 编译通不过请教一个C++问题
C++ online Test 一题C++问题
问个C++模板定义的问题今早google电面报告
问一道C++ template的面试题C++ template Questions
相关话题的讨论汇总
话题: files话题: stl话题: val话题: template话题: temp