Accessing public members of base class fails

Hi guys,

might be a bit of a coward-ish question: I've got two classes, and declared all variables public. Why can't I access the variables from derived class??

g++ tells me: vec3d.h:76:3: error: ‘val’ was not declared in this scope

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
template<typename TYPE>
class vec{
public:
/**
 * \var *val 
 * \brief *val is a pointer on a dynamically allocated array of TYPES
*/
        TYPE *val;
/**
 * \var dimension
 * \brief an integer value storing the size of the array
*/
        int dimension;
public:
/**
 * \fn vec()
 * \brief (constructor)
 * 
 * With no arguments an array of one TYPE is set up, and filled with 0
*/
        vec();
/**
 * \fn vec( TYPE right )
 * \brief (constructor)
 * \param[in] right the value the vector will be initialised with
 */
        vec( TYPE right );

/**
 * \fn vec( TYPE right, int _dimension )
 * \brief (constructor)
 * \param[in] right the value all vector fields are initialised with
 * \param[in] _dimension the size of the array
*/
        vec( TYPE right, int _dimension );

[etc]


and

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
template<typename TYPE>
class vec3d : public vec<TYPE>{
public:

/**
 * \fn vec3d()
 * \brief (constructor)
 * 
 * With no arguments an array of 3 TYPEs is set up, and filled with 0
*/
        vec3d() : vec<TYPE>( 0, 3 ){};
/**
 * \fn vec3d( TYPE right )
 * \brief (constructor)
 * \param[in] right the value the vector will be initialised with
 */
        vec3d( TYPE right ) : vec<TYPE>( right, 3 ){};
/**
 * \fn vec3d( TYPE X_val, TYPE Y_val, TYPE Z_val )
 * \brief (constructor)
 * \param[in] X_val the value vec3d[0] fiels is initialised with
 * \param[in] Y_val the value vec3d[1] fiels is initialised with
 * \param[in] Z_val the value vec3d[2] fiels is initialised with
*/
        vec3d( TYPE X_val, TYPE Y_val, TYPE Z_val ) : vec<TYPE>( 0, 3 ){
                val[0] = X_val; //// <----------THIS ONE FAILS!
                val[1] = Y_val;
                val[2] = Z_val;
        };
[etc]


Nevermind! this->val works!
And if you want to know why you have to do it like this, check this out:
http://www.comeaucomputing.com/techtalk/templates/#whythisarrow
Interesting, they should link such stuff in their tutorials! Thanks!
Topic archived. No new replies allowed.