C++ C++;错误:类没有名为的成员
我有这个问题C++ C++;错误:类没有名为的成员,c++,dtn,C++,Dtn,我有这个问题 MemoryBundleStorage.cpp: In member function 'virtual void dtn::storage::MemoryBundleStorage::store(const dtn::data::Bundle&)': MemoryBundleStorage.cpp:146:67: error: 'const class dtn::data::Bundle' has no member named 'getClass' MemoryBund
MemoryBundleStorage.cpp: In member function 'virtual void dtn::storage::MemoryBundleStorage::store(const dtn::data::Bundle&)':
MemoryBundleStorage.cpp:146:67: error: 'const class dtn::data::Bundle' has no member named 'getClass'
MemoryBundleStorage.cpp:150:19: error: 'const class dtn::data::Bundle' has no member named 'getClass'
在Eclipse中编译此函数时
void MemoryBundleStorage::store(const dtn::data::Bundle &bundle)
{
std::cout << "MemoryBundleStorage store" << std::endl;
ibrcommon::MutexLock l(_bundleslock);
std::cout << "Storing bundle(Memory). His class is " << bundle.getClass() << std::endl; //<<Here ERROR
}
方法getClass()的实现如下(Bundle.cpp)
名称空间dtn
{
命名空间数据
{
Bundle::Bundle()
{
//如果未设置时间戳,请添加ageblock
如果(_timestamp==0)
{
//添加新的ageblock
向前推();
}
}
int Bundle::getClass()常量{
无论什么
}
}
我做错了什么?也许电话打得不好
谢谢
Edit1:完整的bundle.h
#ifndef BUNDLE_H_
#define BUNDLE_H_
#include "ibrdtn/data/Dictionary.h"
#include "ibrdtn/data/PrimaryBlock.h"
#include "ibrdtn/data/Block.h"
#include "ibrdtn/data/PayloadBlock.h"
#include "ibrdtn/data/EID.h"
#include "ibrdtn/data/ExtensionBlock.h"
#include "ibrcommon/refcnt_ptr.h"
#include <ostream>
#ifdef __DEVELOPMENT_ASSERTIONS__
#include <cassert>
#endif
#include <set>
#include <map>
#include <typeinfo>
namespace dtn
{
namespace security
{
class StrictSerializer;
class MutualSerializer;
}
namespace data
{
class CustodySignalBlock;
class StatusReportBlock;
class Bundle : public PrimaryBlock
{
friend class DefaultSerializer;
friend class DefaultDeserializer;
friend class dtn::security::StrictSerializer;
friend class dtn::security::MutualSerializer;
public:
int getClass() const;
class NoSuchBlockFoundException : public ibrcommon::Exception
{
public:
NoSuchBlockFoundException() : ibrcommon::Exception("No block found with this Block ID.")
{
};
};
enum BUNDLE_CLASS
{
};
class BlockList
{
friend class DefaultSerializer;
friend class DefaultDeserializer;
friend class dtn::security::StrictSerializer;
friend class dtn::security::MutualSerializer;
public:
BlockList();
virtual ~BlockList();
BlockList& operator=(const BlockList &ref);
void push_front(Block *block);
void push_back(Block *block);
void insert(Block *block, const Block *before);
void remove(const Block *block);
void clear();
const std::set<dtn::data::EID> getEIDs() const;
Block& get(int index);
const Block& get(int index) const;
template<class T> T& get();
template<class T> const T& get() const;
template<class T>
const std::list<const T*> getList() const;
const std::list<const Block*> getList() const;
size_t size() const;
private:
std::list<refcnt_ptr<Block> > _blocks;
};
Bundle();
virtual ~Bundle();
bool operator==(const Bundle& other) const;
bool operator!=(const Bundle& other) const;
bool operator<(const Bundle& other) const;
bool operator>(const Bundle& other) const;
const std::list<const dtn::data::Block*> getBlocks() const;
dtn::data::Block& getBlock(int index);
const dtn::data::Block& getBlock(int index) const;
template<class T>
T& getBlock();
template<class T>
const T& getBlock() const;
template<class T>
const std::list<const T*> getBlocks() const;
template<class T>
T& push_front();
template<class T>
T& push_back();
template<class T>
T& insert(const dtn::data::Block &before);
dtn::data::PayloadBlock& push_front(ibrcommon::BLOB::Reference &ref);
dtn::data::PayloadBlock& push_back(ibrcommon::BLOB::Reference &ref);
dtn::data::PayloadBlock& insert(const dtn::data::Block &before, ibrcommon::BLOB::Reference &ref);
dtn::data::Block& push_front(dtn::data::ExtensionBlock::Factory &factory);
dtn::data::Block& push_back(dtn::data::ExtensionBlock::Factory &factory);
dtn::data::Block& insert(dtn::data::ExtensionBlock::Factory &factory, const dtn::data::Block &before);
void remove(const dtn::data::Block &block);
void clearBlocks();
string toString() const;
size_t blockCount() const;
private:
BlockList _blocks;
};
template<class T>
const std::list<const T*> Bundle::getBlocks() const
{
return _blocks.getList<T>();
}
template<class T>
T& Bundle::getBlock()
{
return _blocks.get<T>();
}
template<class T>
const T& Bundle::getBlock() const
{
return _blocks.get<T>();
}
template<>
CustodySignalBlock& Bundle::BlockList::get<CustodySignalBlock>();
template<>
const CustodySignalBlock& Bundle::BlockList::get<const CustodySignalBlock>() const;
template<>
StatusReportBlock& Bundle::BlockList::get<StatusReportBlock> ();
template<>
const StatusReportBlock& Bundle::BlockList::get<const StatusReportBlock>() const;
template<class T>
const T& Bundle::BlockList::get() const
{
try {
// copy all blocks to the list
for (std::list<refcnt_ptr<Block> >::const_iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
{
if ((*iter)->getType() == T::BLOCK_TYPE)
{
const Block *b = (*iter).getPointer();
return dynamic_cast<const T&>(*b);
}
}
} catch (const std::bad_cast&) {
}
throw NoSuchBlockFoundException();
}
template<class T>
T& Bundle::BlockList::get()
{
try {
// copy all blocks to the list
for (std::list<refcnt_ptr<Block> >::iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
{
if ((*iter)->getType() == T::BLOCK_TYPE)
{
Block *b = (*iter).getPointer();
return dynamic_cast<T&>(*b);
}
}
} catch (const std::bad_cast&) {
}
throw NoSuchBlockFoundException();
}
template<class T>
const std::list<const T*> Bundle::BlockList::getList() const
{
// create a list of blocks
std::list<const T*> ret;
// copy all blocks to the list
for (std::list<refcnt_ptr<Block> >::const_iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
{
if ((*(*iter)).getType() == T::BLOCK_TYPE)
{
const T* obj = dynamic_cast<const T*>((*iter).getPointer());
if (obj != NULL)
{
ret.push_back( obj );
}
}
}
return ret;
}
template<class T>
T& Bundle::push_front()
{
T *tmpblock = new T();
dtn::data::Block *block = dynamic_cast<dtn::data::Block*>(tmpblock);
#ifdef __DEVELOPMENT_ASSERTIONS__
assert(block != NULL);
#endif
_blocks.push_front(block);
return (*tmpblock);
}
template<class T>
T& Bundle::push_back()
{
T *tmpblock = new T();
dtn::data::Block *block = dynamic_cast<dtn::data::Block*>(tmpblock);
#ifdef __DEVELOPMENT_ASSERTIONS__
assert(block != NULL);
#endif
_blocks.push_back(block);
return (*tmpblock);
}
template<class T>
T& Bundle::insert(const dtn::data::Block &before)
{
T *tmpblock = new T();
dtn::data::Block *block = dynamic_cast<dtn::data::Block*>(tmpblock);
#ifdef __DEVELOPMENT_ASSERTIONS__
assert(block != NULL);
#endif
_blocks.insert(block, &before);
return (*tmpblock);
}
}
}
#endif /* BUNDLE_H_ */
\ifndef BUNDLE\u H_
#定义BUNDLE_H_
#包括“ibrdtn/data/Dictionary.h”
#包括“ibrdtn/data/PrimaryBlock.h”
#包括“ibrdtn/data/Block.h”
#包括“ibrdtn/data/PayloadBlock.h”
#包括“ibrdtn/data/EID.h”
#包括“ibrdtn/data/ExtensionBlock.h”
#包括“IBRComon/refcnt_ptr.h”
#包括
#ifdef uu开发u断言__
#包括
#恩迪夫
#包括
#包括
#包括
名称空间dtn
{
命名空间安全性
{
类序列化器;
类多联调压器;
}
命名空间数据
{
类托管签名锁;
类状态报告块;
类束:公共主块
{
朋友类默认序列化程序;
朋友类DefaultDeserializer;
朋友类dtn::security::StrictSerializer;
friend类dtn::security::MutualSerializer;
公众:
int getClass()常量;
类NoSuchBlockFoundException:public IBRComon::Exception
{
公众:
NoSuchBlockFoundException():IBRComon::Exception(“未找到具有此块ID的块”)
{
};
};
enum BUNDLE_类
{
};
类阻止列表
{
朋友类默认序列化程序;
朋友类DefaultDeserializer;
朋友类dtn::security::StrictSerializer;
friend类dtn::security::MutualSerializer;
公众:
区块列表();
虚拟~BlockList();
块列表和运算符=(常量块列表和参考);
无效推前(块*块);
无效推回(块*块);
无效插入(块*块,常数块*之前);
空洞移除(常数块*块);
无效清除();
常量std::set getEIDs()常量;
Block&get(int索引);
const Block&get(int索引)const;
模板T&get();
模板常量T&get()常量;
模板
常量std::list getList()常量;
常量std::list getList()常量;
大小\u t大小()常量;
私人:
标准::列表块;
};
束();
虚拟束();
布尔运算符==(常量束和其他)常量;
布尔运算符!=(常数束和其他)常数;
布尔运算符(常数束和其他)常数;
常量std::list getBlocks()常量;
dtn::data::Block和getBlock(int索引);
常量dtn::data::Block&getBlock(int索引)常量;
模板
T&getBlock();
模板
常量T&getBlock()常量;
模板
常量std::list getBlocks()常量;
模板
T&push_front();
模板
T&push_back();
模板
插入(&insert)(常量dtn::数据::块和之前);
dtn::data::PayloadBlock和push_front(IBRComon::BLOB::Reference和ref);
dtn::data::PayloadBlock和push_-back(IBRComon::BLOB::Reference和ref);
dtn::data::PayloadBlock&insert(常量dtn::data::Block&before,IBRComon::BLOB::Reference&ref);
dtn::data::Block&push_front(dtn::data::ExtensionBlock::Factory&Factory);
dtn::data::Block&push_back(dtn::data::ExtensionBlock::Factory&Factory);
dtn::data::Block&insert(dtn::data::ExtensionBlock::Factory&Factory,常量dtn::data::Block&before);
void remove(const dtn::data::Block&Block);
空块();
字符串toString()常量;
大小\u t blockCount()常量;
私人:
区块列表(区块);;
};
模板
常量std::列表包::getBlocks()常量
{
返回_blocks.getList();
}
模板
T&Bundle::getBlock()
{
return_blocks.get();
}
模板
常量T&Bundle::getBlock()常量
{
return_blocks.get();
}
模板
CustodySignalBlock&Bundle::BlockList::get();
模板
const CustodySignalBlock&Bundle::BlockList::get()const;
模板
StatusReportBlock&Bundle::BlockList::get();
模板
const StatusReportBlock&Bundle::BlockList::get()const;
模板
常量T&Bundle::BlockList::get()常量
{
试一试{
//将所有块复制到列表中
对于(std::list::const_iterator iter=_blocks.begin();iter!=_blocks.end();iter++)
{
if((*iter)->getType()==T::BLOCK_TYPE)
{
常量块*b=(*iter).getPointer();
返回动态_cast(*b);
}
}
}捕获(常量标准::错误的\u投射&){
}
抛出NoSuchBlockFoundException();
}
模板
T&Bundle::BlockList::get()
{
试一试{
//将所有块复制到列表中
for(std::list::迭代器)
namespace dtn
{
namespace data
{
Bundle::Bundle()
{
// if the timestamp is not set, add a ageblock
if (_timestamp == 0)
{
// add a new ageblock
push_front<dtn::data::AgeBlock>();
}
}
int Bundle::getClass() const{
whatever
}
}
#ifndef BUNDLE_H_
#define BUNDLE_H_
#include "ibrdtn/data/Dictionary.h"
#include "ibrdtn/data/PrimaryBlock.h"
#include "ibrdtn/data/Block.h"
#include "ibrdtn/data/PayloadBlock.h"
#include "ibrdtn/data/EID.h"
#include "ibrdtn/data/ExtensionBlock.h"
#include "ibrcommon/refcnt_ptr.h"
#include <ostream>
#ifdef __DEVELOPMENT_ASSERTIONS__
#include <cassert>
#endif
#include <set>
#include <map>
#include <typeinfo>
namespace dtn
{
namespace security
{
class StrictSerializer;
class MutualSerializer;
}
namespace data
{
class CustodySignalBlock;
class StatusReportBlock;
class Bundle : public PrimaryBlock
{
friend class DefaultSerializer;
friend class DefaultDeserializer;
friend class dtn::security::StrictSerializer;
friend class dtn::security::MutualSerializer;
public:
int getClass() const;
class NoSuchBlockFoundException : public ibrcommon::Exception
{
public:
NoSuchBlockFoundException() : ibrcommon::Exception("No block found with this Block ID.")
{
};
};
enum BUNDLE_CLASS
{
};
class BlockList
{
friend class DefaultSerializer;
friend class DefaultDeserializer;
friend class dtn::security::StrictSerializer;
friend class dtn::security::MutualSerializer;
public:
BlockList();
virtual ~BlockList();
BlockList& operator=(const BlockList &ref);
void push_front(Block *block);
void push_back(Block *block);
void insert(Block *block, const Block *before);
void remove(const Block *block);
void clear();
const std::set<dtn::data::EID> getEIDs() const;
Block& get(int index);
const Block& get(int index) const;
template<class T> T& get();
template<class T> const T& get() const;
template<class T>
const std::list<const T*> getList() const;
const std::list<const Block*> getList() const;
size_t size() const;
private:
std::list<refcnt_ptr<Block> > _blocks;
};
Bundle();
virtual ~Bundle();
bool operator==(const Bundle& other) const;
bool operator!=(const Bundle& other) const;
bool operator<(const Bundle& other) const;
bool operator>(const Bundle& other) const;
const std::list<const dtn::data::Block*> getBlocks() const;
dtn::data::Block& getBlock(int index);
const dtn::data::Block& getBlock(int index) const;
template<class T>
T& getBlock();
template<class T>
const T& getBlock() const;
template<class T>
const std::list<const T*> getBlocks() const;
template<class T>
T& push_front();
template<class T>
T& push_back();
template<class T>
T& insert(const dtn::data::Block &before);
dtn::data::PayloadBlock& push_front(ibrcommon::BLOB::Reference &ref);
dtn::data::PayloadBlock& push_back(ibrcommon::BLOB::Reference &ref);
dtn::data::PayloadBlock& insert(const dtn::data::Block &before, ibrcommon::BLOB::Reference &ref);
dtn::data::Block& push_front(dtn::data::ExtensionBlock::Factory &factory);
dtn::data::Block& push_back(dtn::data::ExtensionBlock::Factory &factory);
dtn::data::Block& insert(dtn::data::ExtensionBlock::Factory &factory, const dtn::data::Block &before);
void remove(const dtn::data::Block &block);
void clearBlocks();
string toString() const;
size_t blockCount() const;
private:
BlockList _blocks;
};
template<class T>
const std::list<const T*> Bundle::getBlocks() const
{
return _blocks.getList<T>();
}
template<class T>
T& Bundle::getBlock()
{
return _blocks.get<T>();
}
template<class T>
const T& Bundle::getBlock() const
{
return _blocks.get<T>();
}
template<>
CustodySignalBlock& Bundle::BlockList::get<CustodySignalBlock>();
template<>
const CustodySignalBlock& Bundle::BlockList::get<const CustodySignalBlock>() const;
template<>
StatusReportBlock& Bundle::BlockList::get<StatusReportBlock> ();
template<>
const StatusReportBlock& Bundle::BlockList::get<const StatusReportBlock>() const;
template<class T>
const T& Bundle::BlockList::get() const
{
try {
// copy all blocks to the list
for (std::list<refcnt_ptr<Block> >::const_iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
{
if ((*iter)->getType() == T::BLOCK_TYPE)
{
const Block *b = (*iter).getPointer();
return dynamic_cast<const T&>(*b);
}
}
} catch (const std::bad_cast&) {
}
throw NoSuchBlockFoundException();
}
template<class T>
T& Bundle::BlockList::get()
{
try {
// copy all blocks to the list
for (std::list<refcnt_ptr<Block> >::iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
{
if ((*iter)->getType() == T::BLOCK_TYPE)
{
Block *b = (*iter).getPointer();
return dynamic_cast<T&>(*b);
}
}
} catch (const std::bad_cast&) {
}
throw NoSuchBlockFoundException();
}
template<class T>
const std::list<const T*> Bundle::BlockList::getList() const
{
// create a list of blocks
std::list<const T*> ret;
// copy all blocks to the list
for (std::list<refcnt_ptr<Block> >::const_iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
{
if ((*(*iter)).getType() == T::BLOCK_TYPE)
{
const T* obj = dynamic_cast<const T*>((*iter).getPointer());
if (obj != NULL)
{
ret.push_back( obj );
}
}
}
return ret;
}
template<class T>
T& Bundle::push_front()
{
T *tmpblock = new T();
dtn::data::Block *block = dynamic_cast<dtn::data::Block*>(tmpblock);
#ifdef __DEVELOPMENT_ASSERTIONS__
assert(block != NULL);
#endif
_blocks.push_front(block);
return (*tmpblock);
}
template<class T>
T& Bundle::push_back()
{
T *tmpblock = new T();
dtn::data::Block *block = dynamic_cast<dtn::data::Block*>(tmpblock);
#ifdef __DEVELOPMENT_ASSERTIONS__
assert(block != NULL);
#endif
_blocks.push_back(block);
return (*tmpblock);
}
template<class T>
T& Bundle::insert(const dtn::data::Block &before)
{
T *tmpblock = new T();
dtn::data::Block *block = dynamic_cast<dtn::data::Block*>(tmpblock);
#ifdef __DEVELOPMENT_ASSERTIONS__
assert(block != NULL);
#endif
_blocks.insert(block, &before);
return (*tmpblock);
}
}
}
#endif /* BUNDLE_H_ */