Solved Help with Base and Derived Class

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat


Dank Tier Donator
May 2, 2015
Hey guys. I'm having some difficulty on deriving certain functions on a class.
Lets say i have the base class CControl.

class CControl
    CControl() {}
    ~CControl() {}
    void Hey() { 
        MessageBoxA(NULL, "CControl hey", "CControl hey", 0);
    std::string m_string = "";
Then, i define a class CButton based on CControl
class CButton: public CControl
    CButton() { m_string = "ButtonLoaded"; }
    ~CButton() {}
Ok. Until now it is fine.

(QUESTION 1) The thing now is that i want to override the Hey() on CControl with a new function on CButton. What do i do?

class CButton: public CControl
    CButton() { m_string = "ButtonLoaded"; }
    ~CButton() {}
    void Hey() { 
        MessageBoxA(NULL, string.c_str(), string.c_str(), 0); // Now it shows the string value
Is this right? Ok.

Now, that should work. Yeah.

But then this comes to another problem.

I have multiple classes derived from the CControl class (CButton, CGroupBox, CTextBox...), but i need to put them all inside only one wrapper, so it should be easier to handle some events they all have in common. So I made a vector<CControl> containing all my Controls(either Buttons or GroupBoxes) but it seems that when i do:

CButton testButton;

void Test_Direct(){
    testButton = CButton();
// MessageBox says: ButtonLoaded

void Test_Vector(){
    std::vector<CControl> Controls = std::vector<CControl>();
    testButton = CButton();
// MessageBox says: CControl hey
(QUESTION 2) Why does Test_Vector() doesnt execute the overriden function by CButton?

Well, basically i want to be able to call Hey() on the different Controls specifically for the control type, not the base type. How do i do it? I think it have something with Virtual. I tryied playing with that but no sucess.

Last edited:


Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
To be able to effectively do that you'd want hey to be a virtual function and then you can define it however you want for any class that derives from ccontrol

class CControl
virtual void Hey() = 0;

class CButton : CControl
void Hey(){ cout << "Yo" << endl; } 
Edit: Example with my old gui code
#pragma region Element
	class Element {
		An element needs to have a position relative to the WINDOW.
		Some will have dimensions that are variable, others will have set dimensions.
		Color ( relevant to select areas on certain elements )
		A string that may be used for certain things.
		Vector2D relativePosition, dimensions;
		Color elementColor;
		std::string text;
		Window * parent;
		Element( );
		Element( Vector2D rel , Vector2D dim , Color col , std::string text , Window * parent );

		void SetPosition( Vector2D v );

		//Relative Position
		const Vector2D GetPosition( );

		void SetColor( Color col );

		void SetText( std::string newText );

		const Vector2D GetDimensions( );

		Window * GetParent( );
		void SetParent( Window * parent );

		virtual void Draw( )		= 0; // Abstraction bois, different draw for different kin folk.
		virtual void Update( )		= 0;
		virtual bool InBounds( Vector2D mousePos )	= 0;
#pragma endregion

#pragma region Tabs
	class Tab : Element {
		// aight, what does a tab need?
		// has the name. it can have width, thats pretty much it i guess.
		// oh cool wait.
		int index;
		bool selected;
		std::vector<Element *> vTabElements;

		Tab( ) { }
		Tab( int index , UI::Color color , std::string text, Window * parent );

		bool GetSelected( );
		void SetSelected( bool sel );

		void AddElement( Element * ele );

		void Draw( );
		void Update( );
		bool InBounds( UI::Vector2D mousePos );

#pragma endregion
Draw, update and inbounds are the functions to be overridden


Meme Tier VIP
Aug 19, 2012
ewwwww, I dont like it xD So much stuff missing like a few getters, Eventcallbacks etc etc and its always better to put stuff

using Element::xy; (here in tab) into the code, so you can go in the tab header and see all stuff without switching between headers + its more clean
and you reduce the chance of forgetting stuff

whatever if you code alone it doesnt matter after all ^^ And you said its a old code, so you might do it better now
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods