Why does this fail to compile?
Why does this fail to compile?
- Subject: Why does this fail to compile?
- From: Jamie Cho <email@hidden>
- Date: Fri, 16 Nov 2007 05:25:50 -0500
Hi,
I am writing some template classes using the STL iterators. When I
compile the code below, I get the following errors from XCode 3.0:
/Users/jcho/CompilingProblem/Vector.h: In member function 'std::string
jcho::Vector<T>::to_string() const':
/Users/jcho/CompilingProblem/Vector.h:31: error: expected `;' before
'iter'
/Users/jcho/CompilingProblem/Vector.h:32: error: 'iter' was not
declared in this scope
This problem only happens when Vector is a template class. What am I
doing wrong?
Thanks,
Jamie
namespace jcho {
template<class T>
class Vector {
public:
// Create a Vector with count elements of val
Vector(int count=0, T val=0) {
for(int ii=0; ii<count; ii++)
_storage.push_back(val);
}
// Convert the vector into a string
std::string to_string() const {
std::stringstream out;
typedef std::vector<T> vector_t;
vector_t::const_iterator iter = _storage.begin();
for(; iter != _storage.end(); iter++)
out << (*iter);
return out.str();
}
private:
std::vector<T> _storage;
};
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden