5

I have this issue

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'

when compiling this function in 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
}

Partial Bundle.h file

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;

...
}

And the implementation of the method getClass() is the following (Bundle.cpp)

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
                }

}

What am I doing wrong? Maybe the calling is not well done?

Thanks!

Edit1: complete 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_ */
Jay D
  • 3,263
  • 4
  • 32
  • 48
ndarkness
  • 1,011
  • 2
  • 16
  • 36

2 Answers2

1

Does MemoryBundleStorage.cpp include Bundle.h? Forward declaration is not enough if you want to call member functions.

Zlatomir
  • 6,964
  • 3
  • 26
  • 32
0

In cases like that first thing to do is compile asking for the preprocessor output. Then look in that file for the problem, and trace it back to original source. Common causes include macros or include files picked from other directory.

Balog Pal
  • 16,195
  • 2
  • 23
  • 37