Jump to content

cannot access protected member declared in class....but why not?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
alirezan

alirezan

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
Hi

I have this class definition:

HEADER:

extern "C" {

		int  vcl_Connecthandle (int  chan, int  baud, int  bits, int  parity, int  stops, int  flowctl);

		int  vcl_RecvDatahandle (int  chan, const int  * buf, int  len );

		int  vcl_RecvSigHandle (int  chan, int  signal, int  sigarg);

		int  vcl_ResumeHandle (int  chan);

}


class VCH

{

	public:

		VCH();

		VCH (void * Hnd, int  chan);

		~VCH();

		

		int  hndlConnect (int chan, int  baud, int bits, int parity, int stops, int flowctl);

		int  hndlRecvData (int chan, const int * buf, int len );

		int  hndlRecvSig (int chan, int signal, int sigarg);

		int  hndlResume (int chan);

		static VCH * hTable [3];


	protected:

		int  sCl (int chan, int  baud, int bits, int parity, int stops, int flowctl);

		int  RcvD (int chan, const int * buf, int len );

		int  RcvS (int chan, int signal, int sigarg);


	private:

		//bool isMaster;

		void * vchHnd;/* handle to an open VChanLib channel */

		int vchannel;

		int  vclbaud;

		int vclbits, vclparity, vclstops, vclflowctl, vclbrktm;

		bool vclsendBreak;

		int  sndStat;

		

		int vclBuffer [255];

		//int 	ptrBuffer;



};

CPP:

#include "head.h"


extern "C" {

		int  vcl_Connecthandle (int  chan, int  baud, int  bits, int  parity, int  stops, int  flowctl);

		int  vcl_RecvDatahandle (int  chan, const int  * buf, int  len );

		int  vcl_RecvSigHandle (int  chan, int  signal, int  sigarg);

		int  vcl_ResumeHandle (int  chan);

}


int  vcl_Connecthandle (int  chan, int  baud, int  bits, int  parity, int  stops, int  flowctl)

{

	VCH * vhnd = VCH::hTable[chan-1];

	vhnd->sCl (chan, baud, bits, parity, stops, flowctl);

}


when I try to compile it, I get this error message:

Quote

1>c:\users\anematollahi\documents\visual studio 2010\projects\tstclass\tstclass\vch.cpp(13): error C2248: 'VCH::sCl' : cannot access protected member declared in class 'VCH'
1> c:\users\anematollahi\documents\visual studio 2010\projects\tstclass\tstclass\head.h(22) : see declaration of 'VCH::sCl'
1> c:\users\anematollahi\documents\visual studio 2010\projects\tstclass\tstclass\head.h(9) : see declaration of 'VCH'
1>
1>Build FAILED.


Can someone help me figure out why and tell me how I can fix it please?

Thanks

#2
junioridi

junioridi

    Newbie

  • Members
  • Pip
  • 1 posts
I guess you only have permission to access protected methods from inside you inherited classes, otherwise, the member must be public.
The rule is:

1) public members are accessible to anyone.
2) private members are only accessible from inside your class.
3) protected members are accessible from your class and inherited classes.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users