Hello there,

I'm creating kind of a GUI system, and I found myself in trouble when inheriting my base class in my other classes.

This is the gui header:

#ifndef _GUI_H
#define _GUI_H

#define WIN32_MEAN_AND_LEAN
#include <windows.h>
#include <vector>
#include <string>

#define GUI_VERSION 1.0.0.1

#define TRUE 1
#define FALSE 0

#define STRUE "true"
#define SFALSE "false"

#define PGET(p) get_##p()
#define PSET(p,v) set_##p(v)

// Property related
#define DECLARE_PROPERTY(p,t)	t get_##p(); \
								void set_##p(t);
#define DECLARE_RO_PROPERTY(p,t) t get_##p();
#define DECLARE_WO_PROPERTY(p,t) void set_##p(t);

// Number to bool
#define NTOB(n) (n>0)? TRUE : FALSE;

namespace GUI{

	struct COORD_S{
		int x;
		int y;
		COORD_S(int _x, int _y)
		{
			this->x = _x;
			this->y = _y;
		}
		COORD_S()
		{
			COORD_S(0,0);
		}
		COORD_S& operator=(const COORD_S& c)
		{
			if(this == &c) return *this;
			this->x = c.x;
			this->y = c.y;
			return *this;
		}
		COORD_S& operator+(const COORD_S& c)
		{
			if(this == &c) return *this;
			this->x += c.x;
			this->y += c.y;
			return *this;
		}
		COORD_S& operator+(const int i)
		{
			this->x += i;
			this->y += i;
			return *this;
		}
		COORD_S& operator-(const COORD_S& c)
		{
			if(this == &c) return *this;
			this->x -= c.x;
			this->y -= c.y;
			return *this;
		}
		COORD_S& operator-(const int i)
		{
			this->x -= i;
			this->y -= i;
			return *this;
		}
		COORD_S& operator*(const COORD_S& c)
		{
			if(this == &c) return *this;
			this->x = this->x*c.x;
			this->y = this->y*c.y;
			return *this;
		}
		COORD_S& operator*(const int i)
		{
			this->x = this->x*i;
			this->y = this->y*i;
			return *this;
		}
		bool operator==(const COORD_S& c)
		{
			if(this == &c) return true;
			return ((this->x == c.x) && (this->y = c.y));
		}
	};
	struct SIZE_S{
		int width;
		int height;
		SIZE_S(int _w, int _h)
		{
			this->width = _w;
			this->height = _h;
		}
		SIZE_S()
		{
			SIZE_S(0,0);
		}
		SIZE_S& operator=(const SIZE_S& c)
		{
			if(this == &c) return *this;
			this->width = c.width;
			this->height = c.height;
			return *this;
		}
		SIZE_S& operator+(const SIZE_S& c)
		{
			if(this == &c) return *this;
			this->width += c.width;
			this->height += c.height;
			return *this;
		}
		SIZE_S& operator+(const int i)
		{
			this->width += i;
			this->height += i;
			return *this;
		}
		SIZE_S& operator-(const SIZE_S& c)
		{
			if(this == &c) return *this;
			this->width -= c.width;
			this->height -= c.height;
			return *this;
		}
		SIZE_S& operator-(const int i)
		{
			this->width -= i;
			this->height -= i;
			return *this;
		}
		SIZE_S& operator*(const SIZE_S& c)
		{
			if(this == &c) return *this;
			this->width = this->width*c.width;
			this->height = this->height*c.height;
			return *this;
		}
		SIZE_S& operator*(const int i)
		{
			this->width = this->width*i;
			this->height = this->height*i;
			return *this;
		}
		bool operator==(const SIZE_S& c)
		{
			if(this == &c) return true;
			return ((this->width == c.width) && (this->height = c.height));
		}
	};

	// Events
	enum Events{
		EVENT_NULL		= (0<<0),
		EVENT_MOUSE		= (1<<0),
		EVENT_KEYBD		= (1<<1)
	};
	// Mouse events
	enum MouseEvents{
		MOUSE_NULL			= (0<<0),
		MOUSE_MOVE			= (1<<0),
		MOUSE_DOWN			= (1<<1),
		MOUSE_UP			= (1<<2),
		MOUSE_MBUTTON1		= (1<<3),
		MOUSE_MBUTTON2		= (1<<4),
		MOUSE_MBUTTON3		= (1<<5),
		MOUSE_SCROLLUP		= (1<<6),
		MOUSE_SCROLLDOWN	= (1<<7)
	};
	// Keyboard events
	enum KeybdEvents{
		KEYBD_NULL		= (0<<0),
		KEYDB_KEYDOWN	= (1<<0),
		KEYBD_KEYUP		= (1<<1)
	};
	enum{
	};

};

#endif

This is the header of my base class:

#ifndef _OBJECT_H
#define _OBJECT_H

#include "gui.h"

namespace GUI{

	class CObject{
	public:
		CObject();
		CObject(const CObject&);
		virtual ~CObject();
		CObject& operator=(const CObject&);
		const CObject& operator=(const CObject&) const;
		DECLARE_PROPERTY(name,std::string);
	protected:
	private:
		std::string sName;
	};
};

#endif

This is the code of the inheriting class:

#ifndef _CONTROL_H
#define _CONTROL_H

#include "gui.h"
#include "object.h"

namespace GUI{

	class CControl : public CObject{
	public:
		CControl();
		CControl(const CControl&);
		virtual ~CControl();
		CControl& operator=(const CControl&);
		const CControl& operator=(const CControl&) const;
		virtual LRESULT _WndProc(HWND, UINT, WPARAM, LPARAM);
		DECLARE_PROPERTY(parent,CControl*);
		DECLARE_RO_PROPERTY(hwnd,HWND);
	protected:
		static LRESULT CALLBACK WndProc( HWND , UINT , WPARAM , LPARAM );
	private:
		HWND m_hWnd;
		CControl *m_parent;
	};

};

#endif

The errors I get are the following:
- when trying to get/set the name of the object using the get_name/set_name functions, the compiler gives me the following error:

error C2662: 'GUI::CObject::get_name' : cannot convert 'this' pointer from 'const GUI::CControl' to 'GUI::CObject &'

- when trying to get/set the hwnd or parent of a control, i get the following error:

error C2662: 'GUI::CControl::get_hwnd' : cannot convert 'this' pointer from 'const GUI::CControl' to 'GUI::CControl &'

Anyone knows what is going on here?

Grtz, Tom.

It would help to see the code which is calling these methods. Are you trying to call get_name() from a constant CControl object?

This article has been dead for over six months. Start a new discussion instead.