Jump to content
  • Advertisement
Sign in to follow this  
Daniel Miller

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

This topic is 4710 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
Advertisement
Yeah, you're right; I wasn't paying attention. I don't see a problem, but then I haven't used C++ in a year or so.

Share this post


Link to post
Share on other sites
MSVC7.1 (.NET 2003) insists on a typename keyword, other than that it compiles fine.

Scanline(typename std::vector<PixelType>::size_type size)

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!