title: C ++ error: class has no member named
body: <p>I have this issue</p>
  
  <pre><code>MemoryBundleStorage.cpp: In member function 'virtual void dtn::storage::MemoryBundleStorage::store(const dtn::data::Bundle&amp;)':
  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'
  </code></pre>
  
  <p>when compiling this function in Eclipse</p>
  
  <pre><code>void MemoryBundleStorage::store(const dtn::data::Bundle &amp;bundle)
          {
              std::cout &lt;&lt; "MemoryBundleStorage store" &lt;&lt; std::endl;
              ibrcommon::MutexLock l(_bundleslock);
              std::cout &lt;&lt; "Storing bundle(Memory). His class is " &lt;&lt; bundle.getClass() &lt;&lt; std::endl; //&lt;&lt;Here ERROR
  }
  </code></pre>
  
  <p>Partial Bundle.h file</p>
  
  <pre><code>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;
  
  ...
  }
  </code></pre>
  
  <p>And the implementation of the method getClass() is the following (Bundle.cpp)</p>
  
  <pre><code>namespace dtn
  {
      namespace data
      {
          Bundle::Bundle()
          {
              // if the timestamp is not set, add a ageblock
              if (_timestamp == 0)
              {
                  // add a new ageblock
                  push_front&lt;dtn::data::AgeBlock&gt;();
              }
          }
  
          int Bundle::getClass() const{
                   whatever
                  }
  
  }
  </code></pre>
  
  <p>What am I doing wrong? Maybe the calling is not well done?</p>
  
  <p>Thanks!</p>
  
  <p>Edit1: complete bundle.h</p>
  
  <pre><code>#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 &lt;ostream&gt;
  #ifdef __DEVELOPMENT_ASSERTIONS__
  #include &lt;cassert&gt;
  #endif
  #include &lt;set&gt;
  #include &lt;map&gt;
  #include &lt;typeinfo&gt;
  
  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&amp; operator=(const BlockList &amp;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&lt;dtn::data::EID&gt; getEIDs() const;
  
                  Block&amp; get(int index);
                  const Block&amp; get(int index) const;
                  template&lt;class T&gt; T&amp; get();
                  template&lt;class T&gt; const T&amp; get() const;
  
                  template&lt;class T&gt;
                  const std::list&lt;const T*&gt; getList() const;
  
                  const std::list&lt;const Block*&gt; getList() const;
  
                  size_t size() const;
  
              private:
                  std::list&lt;refcnt_ptr&lt;Block&gt; &gt; _blocks;
              };
  
              Bundle();
              virtual ~Bundle();
  
              bool operator==(const Bundle&amp; other) const;
              bool operator!=(const Bundle&amp; other) const;
              bool operator&lt;(const Bundle&amp; other) const;
              bool operator&gt;(const Bundle&amp; other) const;
  
              const std::list&lt;const dtn::data::Block*&gt; getBlocks() const;
  
              dtn::data::Block&amp; getBlock(int index);
              const dtn::data::Block&amp; getBlock(int index) const;
  
              template&lt;class T&gt;
              T&amp; getBlock();
  
              template&lt;class T&gt;
              const T&amp; getBlock() const;
  
              template&lt;class T&gt;
              const std::list&lt;const T*&gt; getBlocks() const;
  
              template&lt;class T&gt;
              T&amp; push_front();
  
              template&lt;class T&gt;
              T&amp; push_back();
  
              template&lt;class T&gt;
              T&amp; insert(const dtn::data::Block &amp;before);
  
              dtn::data::PayloadBlock&amp; push_front(ibrcommon::BLOB::Reference &amp;ref);
              dtn::data::PayloadBlock&amp; push_back(ibrcommon::BLOB::Reference &amp;ref);
              dtn::data::PayloadBlock&amp; insert(const dtn::data::Block &amp;before, ibrcommon::BLOB::Reference &amp;ref);
  
              dtn::data::Block&amp; push_front(dtn::data::ExtensionBlock::Factory &amp;factory);
              dtn::data::Block&amp; push_back(dtn::data::ExtensionBlock::Factory &amp;factory);
              dtn::data::Block&amp; insert(dtn::data::ExtensionBlock::Factory &amp;factory, const dtn::data::Block &amp;before);
  
              void remove(const dtn::data::Block &amp;block);
              void clearBlocks();
  
              string toString() const;
  
              size_t blockCount() const;
  
          private:
              BlockList _blocks;
          };
  
          template&lt;class T&gt;
          const std::list&lt;const T*&gt; Bundle::getBlocks() const
          {
              return _blocks.getList&lt;T&gt;();
          }
  
          template&lt;class T&gt;
          T&amp; Bundle::getBlock()
          {
              return _blocks.get&lt;T&gt;();
          }
  
          template&lt;class T&gt;
          const T&amp; Bundle::getBlock() const
          {
              return _blocks.get&lt;T&gt;();
          }
  
          template&lt;&gt;
          CustodySignalBlock&amp; Bundle::BlockList::get&lt;CustodySignalBlock&gt;();
  
          template&lt;&gt;
          const CustodySignalBlock&amp; Bundle::BlockList::get&lt;const CustodySignalBlock&gt;() const;
  
          template&lt;&gt;
          StatusReportBlock&amp; Bundle::BlockList::get&lt;StatusReportBlock&gt; ();
  
          template&lt;&gt;
          const StatusReportBlock&amp; Bundle::BlockList::get&lt;const StatusReportBlock&gt;() const;
  
          template&lt;class T&gt;
          const T&amp; Bundle::BlockList::get() const
          {
              try {
                  // copy all blocks to the list
                  for (std::list&lt;refcnt_ptr&lt;Block&gt; &gt;::const_iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
                  {
                      if ((*iter)-&gt;getType() == T::BLOCK_TYPE)
                      {
                          const Block *b = (*iter).getPointer();
                          return dynamic_cast&lt;const T&amp;&gt;(*b);
                      }
                  }
              } catch (const std::bad_cast&amp;) {
  
              }
  
              throw NoSuchBlockFoundException();
          }
  
          template&lt;class T&gt;
          T&amp; Bundle::BlockList::get()
          {
              try {
                  // copy all blocks to the list
                  for (std::list&lt;refcnt_ptr&lt;Block&gt; &gt;::iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
                  {
                      if ((*iter)-&gt;getType() == T::BLOCK_TYPE)
                      {
                          Block *b = (*iter).getPointer();
                          return dynamic_cast&lt;T&amp;&gt;(*b);
                      }
                  }
              } catch (const std::bad_cast&amp;) {
  
              }
  
              throw NoSuchBlockFoundException();
          }
  
          template&lt;class T&gt;
          const std::list&lt;const T*&gt; Bundle::BlockList::getList() const
          {
              // create a list of blocks
              std::list&lt;const T*&gt; ret;
  
              // copy all blocks to the list
              for (std::list&lt;refcnt_ptr&lt;Block&gt; &gt;::const_iterator iter = _blocks.begin(); iter != _blocks.end(); iter++)
              {
                  if ((*(*iter)).getType() == T::BLOCK_TYPE)
                  {
                      const T* obj = dynamic_cast&lt;const T*&gt;((*iter).getPointer());
  
                      if (obj != NULL)
                      {
                          ret.push_back( obj );
                      }
                  }
              }
  
              return ret;
          }
  
          template&lt;class T&gt;
          T&amp; Bundle::push_front()
          {
              T *tmpblock = new T();
              dtn::data::Block *block = dynamic_cast&lt;dtn::data::Block*&gt;(tmpblock);
  
  #ifdef __DEVELOPMENT_ASSERTIONS__
              assert(block != NULL);
  #endif
  
              _blocks.push_front(block);
              return (*tmpblock);
          }
  
          template&lt;class T&gt;
          T&amp; Bundle::push_back()
          {
              T *tmpblock = new T();
              dtn::data::Block *block = dynamic_cast&lt;dtn::data::Block*&gt;(tmpblock);
  
  #ifdef __DEVELOPMENT_ASSERTIONS__
              assert(block != NULL);
  #endif
  
              _blocks.push_back(block);
              return (*tmpblock);
          }
  
          template&lt;class T&gt;
          T&amp; Bundle::insert(const dtn::data::Block &amp;before)
          {
              T *tmpblock = new T();
              dtn::data::Block *block = dynamic_cast&lt;dtn::data::Block*&gt;(tmpblock);
  
  #ifdef __DEVELOPMENT_ASSERTIONS__
              assert(block != NULL);
  #endif
  
              _blocks.insert(block, &amp;before);
              return (*tmpblock);
          }
      }
  }
  
  #endif /* BUNDLE_H_ */
  </code></pre>