帮忙把这段c++代码翻译成java ,,谢啦

zh2332926106 2011-09-21 09:05:33
头文件
ErrorCode.h

namespace hg{
namespace network{

class ErrorCode{
protected:
class Impl;

Impl* m_impl;
public:
ErrorCode();
virtual ~ErrorCode();

void assign(int value, const char* message);

int value(void) const;
const char* message(void) const;

operator bool() const;
bool operator!() const;
};

实现部分

ErrorCode.cpp

#include "ErrorCode.h"
#include <string>

namespace hg{
namespace network{

class ErrorCode::Impl{
protected:
int m_value;
std::string m_message;
public:
Impl();
virtual ~Impl();

void assign(int value, const char* message);

int value(void) const;
const char* message(void) const;
};

ErrorCode::Impl::Impl() : m_value(0)
{
}

ErrorCode::Impl::~Impl()
{
}

void ErrorCode::Impl::assign(int value, const char* message)
{
m_value = value;
m_message = message;
}

int ErrorCode::Impl::value(void) const
{
return m_value;
}

const char* ErrorCode::Impl::message(void) const
{
return m_message.c_str();
}

/****************************************************************************************/

ErrorCode::ErrorCode() : m_impl(new ErrorCode::Impl())
{
}

ErrorCode::~ErrorCode()
{
delete m_impl;
}

void ErrorCode::assign(int value, const char* message)
{
m_impl->assign(value, message);
}

int ErrorCode::value(void) const
{
return m_impl->value();
}

const char* ErrorCode::message(void) const
{
return m_impl->message();
}

ErrorCode::operator bool() const
{
return m_impl->value() == 0 ? false : true;
}

bool ErrorCode::operator!() const
{
return m_impl->value() == 0;
}
...全文
109 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fox000002 2011-09-21
  • 打赏
  • 举报
回复
差不多是这样子

package hg.network;

public class ErrorCode
{
private class Impl
{
private int m_value;
private string m_message;
public Impl()
{
m_value = 0;
}

public void assign(int value, string message)
{
m_value = value;
m_message = message;
}

public int value(void)
{
return m_value;
}

public string message(void)
{
return m_message;
}
}

private Impl m_impl;

public ErrorCode()
{
m_impl = new Impl();
}


public void assign(int value, string message)
{
m_impl.assign(value, message);
}

public int value(void)
{
return m_impl.value();
}

public string message(void)
{
return m_impl.message();
}


public boolean is_valid()
{
return m_impl->value() == 0 ? false : true;
}
}

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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