[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

C++ og adgang til variable i klassen



Hej

Jeg har nogle problemer med at faa adgang til variable i en klasse.

Jeg har foelgende to klasser

class CA {
public:
  CA() {}
  ~CA() {}
  int x;
private:
  int y;
};

class CB : public CA {
public:
  CB() {}
  ~CB() {}
  int z;
private:
  int w;
};

Saa har jeg koden

void Test(CB* MyB) {

	// OK
	MyB->x = 1;

	// Ikke OK. y er private.
	MyB->y = 1;

	// Burde vaere OK, men
	MyB->z = 1;
	// Compiler siger : 'class CA' has no member named 'z'
}
	
1) Hvorfor siger compileren 'class CA' naar MyB er en pointer til class CB?

2) Hvorfor kan jeg ikke faa adgang til z ?

3) Hvad goer man saa ? (Ikke saa smart at aendre en hel masse i class CA.)

mvh.

Peter

 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-05-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *