• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why does this fail to compile?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Why does this fail to compile?
      • From: "Jason Foreman" <email@hidden>
  • Prev by Date: Build error
  • Next by Date: GNU Make project in XCode 3.0?
  • Previous by thread: Build error
  • Next by thread: Re: Why does this fail to compile?
  • Index(es):
    • Date
    • Thread