Sign in to follow this  

It's been so long since I used C++...

This topic is 4515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

template <class PixelType>
class Scanline
{
public:
	Scanline(std::vector<PixelType>::size_type size) //error
	{
		while (pixels.size() < size)
		{
			pixels.push_back(0);
		}
	}

	PixelType& operator[](int x)
	{
		return pixels[x];
	}

private:
	std::vector<PixelType> pixels;
};

What is wrong with that code? I am getting the following error: error C2059: syntax error : ')' It points to the commented line. [Edited by - Daniel Miller on August 1, 2005 3:39:58 PM]

Share this post


Link to post
Share on other sites
In standard-compliant compilers, the "typename" keyword MUST be used to distinguish typenames from static constants within the context of a template. So, where you used "std::vector<PixelType>::size_type", you should add the typename keyword in front of it. I would personally typedef this as well, like the following snippet of code.


template <class PixelType>
class Scanline
{
public:
typedef typename std::vector<PixelType>::size_type size_type;

Scanline(size_type size)
{
while (line.size() < size)
{
pixels.push_back(0);
}
}

PixelType& operator[](size_type x)
{
return pixels[x];
}

private:
std::vector<PixelType> pixels;
};





Share this post


Link to post
Share on other sites
Thanks a lot, that got it working. [smile]

Wow, how long has that been the case (forever, I assume [sad])? More importantly, what about that specific case requires typename?

I had always thought typename was only used like this: template <typename T>.

Share this post


Link to post
Share on other sites

This topic is 4515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this