CEGUI 扩展自己控件 类型转换错误

tan625747 2010-07-07 11:24:45
CEGUITestWindow.h文件


#pragma once
#include "CEGUIBase.h"
#include "CEGUIWindow.h"
#include "CEGUITestWindowProperties.h"


namespace CEGUI
{
namespace TestWindowProperties
{
class SelectedTextColor: public CEGUI::Property
{
public:
SelectedTextColor() : Property(
"SelectedTextColor",
"设置或者获取选择状态下的文字颜色",
"FFFFFFFF")
{}
//设置和获取属性的函数
String get(const PropertyReceiver* receiver) const;
void set(PropertyReceiver* receiver, const String& value);
};
}

class CEGUIEXPORT TestWindow:public Window
{
public:
static const String EventNamespace; //全局事件的事件空间
static const String WidgetTypeName; //窗口类厂的名称
static const String EventLeftClicked;

public:
TestWindow(const String& type, const String& name);
~TestWindow(void){};
void setSelectedTextColour(colour& c);
colour getSelectTextColour();
void addTestWindowProperties(void);

virtual bool testClassName_impl(const String& class_name) const
{
if (class_name=="Combobox") return true;
return Window::testClassName_impl(class_name);
}

private:
colour d_selectTextColor;
static TestWindowProperties::SelectedTextColor d_selectedTextColourProperty;
};

}


CEGUITestWindow.cpp文件


#include "elements/CEGUITestWindow.h"
#include "CEGUIPropertyHelper.h"
#include "CEGUIPropertyHelper.h"

namespace CEGUI
{
const String TestWindow::EventNamespace("TestWindow");
const String TestWindow::WidgetTypeName("CEGUI/TestWindow");
const String TestWindow::EventLeftClicked( "LeftClicked" );

TestWindow::TestWindow(const String& type, const String& name) :
Window(type, name)
{}

void TestWindow::setSelectedTextColour(colour& c)
{
d_selectTextColor = c;
}
colour TestWindow::getSelectTextColour()
{
return d_selectTextColor;
}

void TestWindow::addTestWindowProperties(void)
{
addProperty(&d_selectedTextColourProperty);
}


namespace TestWindowProperties
{

String SelectedTextColor::get (const PropertyReceiver* receiver) const
{
return static_cast<const TestWindow*>(receiver)->getSelectTextColour();//这里出错
}
void SelectedTextColor::set(PropertyReceiver* receiver, const String& value)
{
static_cast<TestWindow*>(receiver)->setSelectedTextColour(PropertyHelper::stringToColour(value));//stringToColour(value));
}
}

}



编译错误

error C2662: 'CEGUI::TestWindow::getSelectTextColour' : cannot convert 'this' pointer from 'const CEGUI::TestWindow' to 'CEGUI::TestWindow &'

CEGUI 库 仿官方CoboBox控件,这是CoboBox 控件其中的一个函数,它的没有问题,为什么我的出现问题呢?

String ValidationString::get(const PropertyReceiver* receiver) const
{
return static_cast<const Combobox*>(receiver)->getValidationString();
}

编写自己的控件,大家看出为什么出错了吗,怎么改呢。
...全文
76 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
老邓 2010-07-07
  • 打赏
  • 举报
回复
把String SelectedTextColor::get (const PropertyReceiver* receiver) const
把红色的const去掉试试?

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧