?
=?ISO-8859-2?Q?Gordan_Kre=B9i=E6?=
I have classic interface/implementation paradigm. That does not work with
stl containers
Call to doAbstract(derivedList) yelds compilation error:
sample.cpp: In function 'int main(int, char**)':
sample.cpp:23: error: no matching function for call to
'doAbstract(std::list<Derived*, std::allocator<Derived*> >&)'
sample.cpp:12: note: candidates are: void doAbstract(const
std::list<Abstract*, std::allocator<Abstract*> >&)
sample.cpp:16: note: void doAbstract(const
boost::shared_ptr<Abstract>&)
For example, I've added (for me) equivalent situation with boost:shared_ptr
template that works normally.
Is this some special feature of boost:shared_ptr that std:list does not
support or I'm missing something? Is there a workaround?
#include <list>
#include <boost/shared_ptr.hpp>
class Abstract {
// whatever...
};
class Derived : public Abstract {
// whatever...
};
void doAbstract(const std::list<Abstract *> &abstractList) {
// something...
}
void doAbstract(const boost::shared_ptr<Abstract> &abstractPtr) {
// something...
}
int main(int argc, char *argv[]) {
std::list<Derived *> derivedList;
doAbstract(derivedList); // does not work?
boost::shared_ptr<Derived> derivedPtr;
doAbstract(derivedPtr); // works...
return 0;
}
// g++ (GCC) 4.1.3 20070629 (prerelease) (Debian 4.1.2-13)
// Boost 1.33.1
stl containers
Call to doAbstract(derivedList) yelds compilation error:
sample.cpp: In function 'int main(int, char**)':
sample.cpp:23: error: no matching function for call to
'doAbstract(std::list<Derived*, std::allocator<Derived*> >&)'
sample.cpp:12: note: candidates are: void doAbstract(const
std::list<Abstract*, std::allocator<Abstract*> >&)
sample.cpp:16: note: void doAbstract(const
boost::shared_ptr<Abstract>&)
For example, I've added (for me) equivalent situation with boost:shared_ptr
template that works normally.
Is this some special feature of boost:shared_ptr that std:list does not
support or I'm missing something? Is there a workaround?
#include <list>
#include <boost/shared_ptr.hpp>
class Abstract {
// whatever...
};
class Derived : public Abstract {
// whatever...
};
void doAbstract(const std::list<Abstract *> &abstractList) {
// something...
}
void doAbstract(const boost::shared_ptr<Abstract> &abstractPtr) {
// something...
}
int main(int argc, char *argv[]) {
std::list<Derived *> derivedList;
doAbstract(derivedList); // does not work?
boost::shared_ptr<Derived> derivedPtr;
doAbstract(derivedPtr); // works...
return 0;
}
// g++ (GCC) 4.1.3 20070629 (prerelease) (Debian 4.1.2-13)
// Boost 1.33.1