I have shared pointers to an interface created through out the program. I also have a list of weak pointers to their implementations in order to call internal update function. The program works, but when I compile it I get warning C4180. The question is, how to get rid of it?

#include <vector>
#include <algorithm>

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/bind.hpp>

int main(int argc, char **argv){
	struct Iface{};
	struct Imp: public Iface{ void Do(){} };
	typedef boost::shared_ptr<Iface> TIf;
	typedef boost::weak_ptr<Imp> TMonitor;
	typedef std::vector<TMonitor> TMonitors;
	TMonitors m;
	std::for_each(
		m.begin(),
		m.end(),
		boost::bind(&Imp::Do,
			boost::bind(&TMonitor::lock, _1)));
	return 0;
}

The warning is:

c:\src\boost_1_34_1\boost/bind.hpp(1575) : warning C4180: qualifier applied to function type has no meaning; ignored
        c:\src\boost_1_34_1\boost/bind.hpp(1609) : see reference to class template instantiation 'boost::_bi::add_cref<Pm,I>' being compiled
        with
        [
            Pm=boost::shared_ptr<main::Imp> (__thiscall boost::weak_ptr<main::Imp>::* )(void),
            I=1
        ]
        .\main.cpp(29) : see reference to class template instantiation 'boost::_bi::dm_result<Pm,A1>' being compiled
        with
        [
            Pm=boost::shared_ptr<main::Imp> (__thiscall boost::weak_ptr<main::Imp>::* )(void),
            A1=boost::arg<1>
        ]

Recommended Answers

All 2 Replies

This has been a well known microsoft c++ (vc7/vc8) compiler bug; the compiler is picking up the wrong template specialization. It is harmless in this particular case (as well as all the other reported cases). the code is only instantiated, but not executed. (he specialization is only used in a return type in an overload that isn't chosen). there does not seem to be a workaround other than modifying the template code (boost library in this case). microsoft has acknowledged this as a bug, but promised no fix. perhaps because it seems to be harmless (so far). see http://archives.free.net.ph/message/20071019.091814.1ab71296.en.html

Thanks. That explains it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.