Sign in to follow this  
TheUnbeliever

Undeclared identifier in derived class - but declared protected?

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
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

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