tornado2.2下可不可以进行操作符重载?

yjukh 2009-05-07 08:41:24
对一些简单的操作符进行重载,编译没有问题,下载时却提示错误。
有没有人遇到过这种情况??
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjukh 2009-06-17
  • 打赏
  • 举报
回复
自己试成功了,重载的声明和实现都得放在.h里面
98440622 2009-05-14
  • 打赏
  • 举报
回复
貌似没发现什么,Simpc在Shell下ld,一切正常,下面代码仅供参考:)

镜像文件工程建议LZ把VxWorks配置中C++组件配置完整试试看。


#include "VxWorks.h"
#include "loglib.h"
#include "BtTypes.hpp"

namespace Bt {

template<typename Type, UInt32 FixedSize = 32>
class AbstractBuffer {
protected:
AbstractBuffer() : m_Size(0) {}

virtual ~AbstractBuffer() = 0;

void copy(const AbstractBuffer& other) {
for (UInt32 i = 0; i < FixedSize; i++) {
m_Buffer[i] = other.m_Buffer[i];
}
m_Size = other.m_Size;
}

UInt32 m_Size;
Type m_Buffer[FixedSize];
};

template<typename Type, UInt32 FixedSize>
inline AbstractBuffer<Type, FixedSize>::~AbstractBuffer() {}

template<typename Type, UInt32 FixedSize = 32>
class SimpleBuffer: public AbstractBuffer<Type, FixedSize> {
typedef AbstractBuffer<Type, FixedSize> Base;
public:
SimpleBuffer() : AbstractBuffer<Type, FixedSize>() {
}

virtual ~SimpleBuffer() {
}

SimpleBuffer(const SimpleBuffer& other) {
copy(other);
}

SimpleBuffer& operator=(const SimpleBuffer& other) {
copy(other);
return (*this);
}

void Push(Type item) {
if (Base::m_Size < FixedSize) {
Base::m_Buffer[Base::m_Size++] = item;
} else {
// TODO : Shall I throw an exception?
}
}

void Assign(UInt32 offset, Type item) {
if (offset < Base::m_Size) {
Base::m_Buffer[offset] = item;
}
}

Type operator[](UInt32 offset) {
if (offset < Base::m_Size) {
return Base::m_Buffer[offset];
} else {
// TODO : Shall I throw an exception, too?
return (Type) Null;
}
}

UInt32 Length() const {
return Base::m_Size;
}

void Clear() {
Base::m_Size = 0;
}

void Reverse() {
}

void Insert(UInt32 offset, Type item) {
}

Bool Remove(Type item) {
if (Base::m_Size > 0) {
UInt32 offset = 0;
while ((offset < Base::m_Size) && (item != Base::m_Buffer[offset])) {
offset++;
}
if (offset < Base::m_Size) {
while (offset < Base::m_Size - 1) {
Base::m_Buffer[offset] = Base::m_Buffer[offset + 1];
offset++;
}
if (Base::m_Size > 0) Base::m_Size--;
return True;
} else {
return False;
}
} else {
return False;
}
}
};

}

Bt::SimpleBuffer<int> Buffer;

void init_buffer() {
for (int i = 0; i < 10; i++) {
Buffer.Push(i);
}
}

void check_buffer() {
for (int i = 0; i < Buffer.Length(); i++) {
if (Buffer[i] == i) {
logMsg("%d Checked\n", i, Buffer[i], 0, 0, 0, 0);
}
}
}
yjukh 2009-05-12
  • 打赏
  • 举报
回复
是的,已经编译成.out了,可下载的时候说符号有错误
但同样的代码在VC2005中都测试过了的
morris88 2009-05-08
  • 打赏
  • 举报
回复
呵呵,什么叫做编译连接没问题,下载到目标板却有问题呢?
maplewasp 2009-05-08
  • 打赏
  • 举报
回复
支持的。
把C++支持包含上。
能把代码贴出来看看么?

2,180

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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