This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

class member access denied


Hi, I need some help with this topic...

I've got a base clase "layer" like this :

class layer
{
protected:
 int num_inputs;
 int num_outputs;
 float *outputs;
 float *inputs;

 friend network;
 friend kohonen_network;
public:
 layer();
 virtual ~layer();
 virtual int calc_out()=0;

};

two dervide classes of "layer"

class input_layer : public layer
{
private:
public:
 input_layer(int,int);
 ~input_layer();
 virtual int calc_out();
};

class network
{

private:
 layer *layer_ptr[MAX_LAYERS];
 int number_of_layers;
 int layer_size[MAX_LAYERS];
 float *buffer;
 fpos_t position;
 unsigned training;

public:
 network();
 virtual ~network();
 void set_training(const unsigned &);
 unsigned get_training_value();
 void get_layer_info();
 void set_up_network();
 void randomize_weights();
 void update_weights(const float);
 void write_weights(FILE *);
 void read_weights(FILE *);
 void list_weights();
 void write_outputs(FILE *);
 void list_outputs();
 void list_errors();
 void forward_prop();
 void backward_prop(float &);
 float fill_IObuffer(FILE *);
 int   set_up_pattern();

};
class kohonen_layer: public layer
{
protected:
 float *weights;
 int winner_index;
 float win_distance;
 int neighborhood_size;

 friend kohonen_network;

public:
 kohonen_layer(int,int,int);
 virtual ~kohonen_layer();
 virtual int calc_out();
 void randomize_weights();
 void update_neigh_size(int);
 void update_weights(const float);
 void list_weights();
 void list_outputs();
 float get_win_dist();

};

And another class :

class kohonen_network
{
private:

 layer *layer_ptr[2];
 int layer_size[2];
 int neighborhood_size;
 float alpha;

public:
 kohonen_network();
 virtual ~kohonen_network();
 void get_layer_info(int,int);
 int set_up_network(int);
 void randomize_weights();
 void update_neigh_size(int);
 void update_weights(const float);
 void list_weights();
 void list_outputs();
 void list_structure(CFile *);
 void get_next_vector(CFile *);
 void process_next_pattern();
 float get_win_dist();
 int   get_win_index();
 int train_network(CFile *inputfile,int period);
};

In kohonen_network class I've declared the member layer_ptr as array of
layer *.

When I'm creating an object of this class I do the following :

 layer_ptr[0] = new input_layer(0,layer_size[0]);
 layer_ptr[1] = new
kohonen_layer(layer_size[0],layer_size[1],neighborhood_size);

So I've redefined each element with a distinct derived class of layer.

My problem is : when I'm trying to get the weights member of kohonen_layer
class thru this statement :
  layer_ptr[1].weights , wich is in a kohonen_network function member (note
tha kohonen_network is declares as friend so has access to private or
protectes members )

I get the following compiler error : error C2039: 'weights' : is not a
member of 'layer'

So, I define an array of pointers to a base class, then , assign each
pointer a derived class, but, I can't acces to member of the derived class ?

I'm compiling this with a Microsoft C++ Compiler.

Thanks in advance.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]