This is mistake:
DummyService.hpp: 35: error: invalid return type of covariant type for 'virtual std :: vector <ResourceBean *, std :: allocator <ResourceBean * → & DummyService :: list (const std :: string &)'
class Bean { public: typedef std::string Path; virtual ~Bean() {}; virtual const Path& getPath() = 0; virtual const std::string& getName() = 0; protected: Bean(); }; class ResourceBean: public Bean { public: ResourceBean(const Path& path, const std::string& contents) : _path(path), _contents(contents) { } virtual ~ResourceBean() { } virtual const Path& getPath(); virtual void setPath(const Path& path); virtual const std::string& getName(); virtual void setName(const std::string& name); private: Path _path; std::string _name; };
The above Bean classes are data representations, and they are used by two different layers. One layer uses the Bean interface to access getters for data. Access to the ResourceBean provided by data access classes (DAOs), which take data from the database (for example) and populate the ResourceBean .
One of the responsibilities of a DAO is to list resources defined in a specific way:
class Service { protected: Service(); public: virtual std::vector<Bean*>& list(const Bean::Path& path) = 0; virtual ~Service(); }; class DummyService: public Service { public: DummyService(); ~DummyService(); virtual std::vector<ResourceBean*>& list(const ResourceBean::Path& path); };
I think the problem is that in std::vector<ResourceBean*> compiler does not understand that Bean actually the base class of ResourceBean .
Any suggestions? I read some similar topics, but some of the solutions did not work in my case. Please indicate if I missed something. Thank you in advance.
source share