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