由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - template question
相关主题
C++ question about template typedefC++ template function type
Cannot use my own container as the underlying container of a stack? (c++)a c++ question
[菜鸟问题]类模板问题vector::iterator不对
c++ template question:请教 C++ std::list iterator 对 template class pointer 的应用问题
C++ 菜鸟问一个关于template 的问题。template 疑问
boost::function 的 syntax 问题请教一下这个template function在gcc下要怎么修改
C++ Q04: template membertemplate
一个关于C++ template和overload的问题Any difference between class and typename identifier?
相关话题的讨论汇总
话题: myvector话题: template话题: iterator话题: class话题: typename
进入Programming版参与讨论
1 (共1页)
j****i
发帖数: 305
1
Trying to write a class with an Iterator member class with template. The
begin(), end(), and << operator reports syntax error. How should I write
these functions correctly? A little confused about how template and member
class work together. Somebody help.
Thanks.
MyVector.h:
#ifndef MYVECTOR_H_
#define MYVECTOR_H_
#include
using namespace std;
template
class MyVector
{
public:
MyVector();
virtual ~MyVector();
void add(const T& t);
class Iterator
{
t****t
发帖数: 6806
2
MyVector::Iterator is a dependent type, so use the keyword "typename"
template
typename MyVector::Iterator MyVector::begin()
// same for end
// <<
{
typename MyVector::Iterator iter;
....

【在 j****i 的大作中提到】
: Trying to write a class with an Iterator member class with template. The
: begin(), end(), and << operator reports syntax error. How should I write
: these functions correctly? A little confused about how template and member
: class work together. Somebody help.
: Thanks.
: MyVector.h:
: #ifndef MYVECTOR_H_
: #define MYVECTOR_H_
: #include
: using namespace std;

j****i
发帖数: 305
3
Amazing! It looks so simple.
I got to read something about dependent vs non-dependent types.
l**a
发帖数: 423
4
好乱,内嵌class不是好习惯
1 (共1页)
进入Programming版参与讨论
相关主题
Any difference between class and typename identifier?C++ 菜鸟问一个关于template 的问题。
共享我的C++面试题目精选boost::function 的 syntax 问题
STL感觉实在太变态了C++ Q04: template member
一个C++ template的问题一个关于C++ template和overload的问题
C++ question about template typedefC++ template function type
Cannot use my own container as the underlying container of a stack? (c++)a c++ question
[菜鸟问题]类模板问题vector::iterator不对
c++ template question:请教 C++ std::list iterator 对 template class pointer 的应用问题
相关话题的讨论汇总
话题: myvector话题: template话题: iterator话题: class话题: typename