Hello there,
I'm currently facing a strange, kind of annoying, problem.
I'm trying to access a protected member of a base class in a derived class.
Here is my code for the base class:
Code:
class Wnd{
public:
Wnd() : m_hWnd(NULL)
{}
Wnd(HWND hWnd) : m_hWnd(hWnd)
{}
operator HWND()
{
return this->m_hWnd;
}
operator HWND() const
{
return ((Wnd*)this)->m_hWnd;
}
void set_text(const char* text)
{
SendMessage(this->m_hWnd,WM_SETTEXT,(WPARAM)NULL,(LPARAM)text);
}
const char* get_text()
{
unsigned int len = SendMessage(this->m_hWnd,WM_GETTEXTLENGTH,(WPARAM)NULL,(LPARAM)NULL);
char *tmp = new char[len];
SendMessage(this->m_hWnd,WM_GETTEXT,(WPARAM)len,(LPARAM)tmp);
return tmp;
}
void set_visible(BOOL visible)
{
ShowWindow(this->m_hWnd,(visible)? SW_SHOW : SW_HIDE);
}
OVERRIDABLE const Wnd& operator =(HWND hWnd)
{
this->m_hWnd = hWnd;
return *this;
}
OVERRIDABLE const Wnd& operator =(const Wnd& wnd)
{
if(this == &wnd) return *this;
this->m_hWnd = wnd.m_hWnd;
return *this;
}
OVERRIDABLE BOOL operator ==(const Wnd& wnd)
{
return (this->m_hWnd == wnd.m_hWnd);
}
OVERRIDABLE BOOL operator ==(HWND hWnd)
{
return (this->m_hWnd == hWnd);
}
void set_hwnd(HWND hWnd)
{
this->m_hWnd = hWnd;
}
HWND get_hwnd()
{
return this->m_hWnd;
}
void set_hwnd(HWND hWnd) const
{
((Wnd*)this)->m_hWnd = hWnd;
}
HWND get_hwnd() const
{
return ((Wnd*)this)->m_hWnd;
}
protected:
HWND m_hWnd;
private:
};
And here is my code for a derived class:
Code:
class Combobox : public Wnd{
public:
void add_string(const char* string)
{
SendMessage(*this,CB_ADDSTRING,(WPARAM)NULL,(LPARAM)string);
}
void delete_string(const char* string)
{
return this->delete_string(SendMessage(*this,CB_FINDSTRINGEXACT,(WPARAM)NULL,(LPARAM)string));
}
void delete_string(unsigned int i)
{
SendMessage(*this,CB_DELETESTRING,(WPARAM)i,(LPARAM)NULL);
}
char* get_string(unsigned int)
{}
void clear()
{
SendMessage(*this,CB_RESETCONTENT,(WPARAM)NULL,(LPARAM)NULL);
}
unsigned int get_selected_index()
{
return SendMessage(*this,CB_GETCURSEL,(WPARAM)NULL,(LPARAM)NULL);
}
char* get_selected_string()
{
unsigned int len = SendMessage(*this,CB_GETLBTEXTLEN,(WPARAM)NULL,(LPARAM)NULL);
char* tmp = new char[len];
SendMessage(*this,CB_GETLBTEXT,(WPARAM)len,(LPARAM)tmp);
return tmp;
}
void set_selected_index(unsigned int i)
{
SendMessage(*this,CB_SETCURSEL,(WPARAM)i,(LPARAM)NULL);
}
const Combobox& operator=(HWND hWnd)
{
this->m_hWnd = hWnd;
return *this;
}
const Combobox& operator=(const Wnd& wnd)
{
if(this == &wnd) return *this;
this->m_hWnd = wnd.m_hWnd;
return *this;
}
const Combobox& operator=(const Combobox& wnd)
{
if(this == &wnd) return *this;
this->m_hWnd = wnd.m_hWnd;
return *this;
}
protected:
private:
};
The error exists in
Code:
const Combobox& operator=(const Wnd& wnd)
, more specific on the 2nd line:
Code:
this->m_hWnd = wnd.m_hWnd;
The full error says:
Code:
error C2248: 'Gui::Wnd::m_hWnd' : cannot access protected member declared in class 'Gui::Wnd'
Any help would be appreciated