• Advertisement
Sign in to follow this  

Undeclared identifier in derived class - but declared protected?

This topic is 3373 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

Substantially cut down code: Matrix.h
#ifndef MATRIX_H
#define MATRIX_H

#include <algorithm>
#include <stdexcept>

namespace Maths
{
	namespace impl
	{
		static const char AT_DOMAIN_MSG[] = "Index must be non-negative and less than or equal to the relevant dimension template parameter.";
	}

	template <unsigned height_, unsigned width_> class Matrix
	{
	protected:
		float elems[height_ * width_];

	public:
		static const unsigned height = height_;
		static const unsigned width = width_;

		Matrix()                               { std::fill(elems, elems + height * width, 0.0f); }
		Matrix(float (&elems)[height * width]) { std::copy(elems, elems + height * width, this->elems); }
	};

	typedef Matrix<4, 4> Matrix44;
	typedef Matrix<3, 3> Matrix33;
}

#endif


Vector.h
#ifndef VECTOR_H
#define VECTOR_H

#include <cmath>
#include "Matrix.h"

namespace Maths
{
	template <unsigned dimension_> struct Vector : Matrix<dimension_, 1>
	{
		static const unsigned dimension = dimension_;

		Vector(const Matrix<dimension, 1>& v)
			: Matrix<dimension, 1>(v)
		{}

		float operator[](int index) const
		{
			if (index >= dimension || index < 0)
				throw std::domain_error(impl::AT_DOMAIN_MSG);

			/* !!! ERROR HERE !!! - elems undeclared identifier? */
			return elems[index];
		}
	};

	struct Vector3 : Vector<3>
	{
		float  x() const { return operator[](0); }
		float  y() const { return operator[](1); }
		float  z() const { return operator[](2); }

		Vector3(const Matrix<3, 1>& v)
			: Vector(v)
		{}
	};
}

#endif


Error is that elems in Vector.h is apparently undeclared. What am I doing wrong? The error disappears if I don't disable language extensions (MSVC++ 2008EE), but that's not really a solution. Is there a way to get VS to tell you when it's using an extension?

Share this post


Link to post
Share on other sites
Advertisement
use return this->elems[index];
Here is a post in which I enquired about it a while ago.
http://www.gamedev.net/community/forums/topic.asp?topic_id=443946

Share this post


Link to post
Share on other sites
I'm going to write this quickly and move on so my head doesn't explode from how dumb C++ is in certain regards. elems is a dependent name, and hence will not be looked up unless its scope is explicitly qualified. Qualify elems to be a member of Matrix, and it should succeed. STUPID STUPID AARGH sorry gotta go

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
I'm going to write this quickly and move on so my head doesn't explode from how dumb C++ is in certain regards. elems is a dependent name, and hence will not be looked up unless its scope is explicitly qualified. Qualify elems to be a member of Matrix, and it should succeed. STUPID STUPID AARGH sorry gotta go


Haha, thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement