Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Matsen

Weird error, or.... ?

This topic is 5858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I get a weird compiler error when trying to access a public function in a base class, from an instance of a derived class. Here is a part of the base class:
  
class CControl
{
public:
	CControl()
	{}

	CControl(HWND _hwnd)
	{
		AttachWindow(_hwnd);
	}

	~CControl()
	{
		DetachWindow();
	}

	/* Destroy
	*/
	virtual BOOL Destroy()
	{
		DetachWindow();
		return DestroyWindow(this->hwnd);
	}

	/* SetFocus
	*/
	virtual HWND SetFocus()
	{
		return ::SetFocus(this->hwnd);
	}
.
.
.
  
The sub class is derived from CControl:
  
class CTest : CControl
{
public:
	CTest();
	CTest(HWND hParent, int id);
.
.
.
  
Now, when I create an instance of CTest and try to access SetFocus or Destroy, like this: ctest.Destroy(), I get this error: error C2248: ''SetFocus'' : cannot access public member declared in class ''CControl'' f:\kod\c++\controls\controlshit\ccontrol.h(33) : see declaration of ''SetFocus'' It''s public, so why can''t I access it??! I''m new to OOP in C++, so don''t get too hard on me Regards Mats

Share this post


Link to post
Share on other sites
Advertisement
i think its because you have forgotten the public keyword, so all functions of CControl wil be private in CTest ...

try:
class CTest : public CControl


T2k

Share this post


Link to post
Share on other sites
Just a thugh (as I''ve never used derived classes), you may need to use this on your CTest class:

class CTest : public CControl

Note the public keyword. I haven''t tried this so don''t count on it working, but it''s just an idea.

Share this post


Link to post
Share on other sites
parklife: nop virtual only means that you can overwrite it in derivates:

class a{
virtual long _1();//should be an error ?
protected:
virtual long _2();
public:
virtual long _3();
}

class b: a{
//can see _2 and _3 in private area and overwrite it there, _1 isnt accessible from derivate
long _2();//overloaded
public:
long _3();//error virtual is private
}
class b: public a{
//_2 is private _3 is public, _1 inaccessible
long _2();//overloaded
public:
long _3();//overloaded
}

//i think thats the way it works (iam not 100% :D )


T2k

Share this post


Link to post
Share on other sites
Thank you -Thork-! It compiles fine now.

Edit: T2k, didn't see your post, thanks!

Regards Mats


[edited by - Matsen on June 6, 2002 10:06:46 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!