Jump to content
  • Advertisement
Sign in to follow this  
Valere

boost::signals + member function problem [solved]

This topic is 4053 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This seems like a trivial problem, and all I should have to do is follow a tutorial, but I can't get boost::signals to compile in my program. The header of the offending class

#include <boost/signal.hpp>
#include <boost/bind.hpp>
class CProblemClass 
{
public:
	CProblemClass (void);
	virtual ~CProblemClass (void);
private:
	boost::signal<void (int)> m_Sig;

public:
	void Test(int iIndex);
};



The body of the offending class
#include "stdafx.h"
#include "ProblemClass.h"

CProblemClass::CProblemClass(void)
{
	sig2.connect(boost::bind(&CProblemClass::Test, this, _1));

CProblemClass::~CProblemClass(void)
{
}

void CProblemClass::Test(int iIndex)
{

}



and the contents of stdafx.h
#if !defined(AFX_STDAFX_H__1235412B0E_545A_4B44_AEEC_43D0EC4449D9__INCLUDED_)
#define AFX_STDAFX_H__1235412B0E_545A_4B44_AEEC_43D0EC4449D9__INCLUDED_

#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers

#ifndef WINVER			
#define WINVER 0x0400		
#endif

#ifndef _WIN32_WINNT		
#define _WIN32_WINNT 0x0400	
#endif						

#ifndef _WIN32_WINDOWS		
#define _WIN32_WINDOWS 0x0410 
#endif

#ifndef _WIN32_IE			
#define _WIN32_IE 0x0501
#endif

#include <afxwin.h>
#include <afxext.h>

#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <wininet.h>

#include <afxdisp.h> 
#include <afxdtctl.h>
#include <afxtempl.h>

#include <atlbase.h>
#include <atlcom.h>
#include <commctrl.h>
#include <atlWin.h>
#include <atlconv.h>
#include <atlstr.h>
#include <winsock2.h>
#include <afxdlgs.h>
#include <atlcoll.h>
#include <afxhtml.h>

#include <map>
#include <vector>
#include "boost\shared_ptr.hpp"

#include "resource.h"
#include "defines.h"

#ifdef _DEBUG
	#define new DEBUG_NEW
#endif

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__1235412B0E_545A_4B44_AEEC_43D0EC4449D9__INCLUDED_)




When I compile, I get the following error: C2059:syntax error:'(' that apears at this point in the boost code:
        // Assign to a function object using the small object optimization
        template<typename FunctionObj>
        void 
        assign_functor(FunctionObj f, function_buffer& functor, mpl::true_)
        {
          new ((void*)&functor.data) FunctionObj(f); //this line
        }



Here's a complete error dump
        boost\function\function_template.hpp(402) : see reference to function template instantiation 'void boost::detail::function::basic_vtable2<R,T0,T1,Allocator>::assign_functor<FunctionObj>(FunctionObj,boost::detail::function::function_buffer &,boost::mpl::true_)' being compiled
        with
        [
            R=bool,
            T0=boost::signals::detail::stored_group,
            T1=boost::signals::detail::stored_group,
            Allocator=std::allocator<boost::function_base>,
            FunctionObj=boost::signals::detail::group_bridge_compare<std::less<int>,int>
        ]
       boost\function\function_template.hpp(279) : see reference to function template instantiation 'bool boost::detail::function::basic_vtable2<R,T0,T1,Allocator>::assign_to<F>(FunctionObj,boost::detail::function::function_buffer &,boost::detail::function::function_obj_tag)' being compiled
        with
        [
            R=bool,
            T0=boost::signals::detail::stored_group,
            T1=boost::signals::detail::stored_group,
            Allocator=std::allocator<boost::function_base>,
            F=boost::signals::detail::group_bridge_compare<std::less<int>,int>,
            FunctionObj=boost::signals::detail::group_bridge_compare<std::less<int>,int>
        ]
        boost\function\function_template.hpp(651) : see reference to function template instantiation 'bool boost::detail::function::basic_vtable2<R,T0,T1,Allocator>::assign_to<Functor>(F,boost::detail::function::function_buffer &)' being compiled
        with
        [
            R=bool,
            T0=boost::signals::detail::stored_group,
            T1=boost::signals::detail::stored_group,
            Allocator=std::allocator<boost::function_base>,
            Functor=boost::signals
::detail::group_bridge_compare<std::less<int>,int>,
            F=boost::signals::detail::group_bridge_compare<std::less<int>,int>
        ]
       boost\function\function_template.hpp(508) : see reference to function template instantiation 'void boost::function2<R,T0,T1>::assign_to<Functor>(Functor)' being compiled
        with
        [
            R=bool,
            T0=boost::signals::detail::stored_group,
            T1=boost::signals::detail::stored_group,
            Functor=boost::signals::detail::group_bridge_compare<std::less<int>,int>
        ]
        boost\signals\signal_template.hpp(198) : see reference to function template instantiation 'boost::function2<R,T0,T1>::function2<boost::signals::detail::group_bridge_compare<Compare,Key>>(Functor,boost::enable_if_c<B,T>::type)' being compiled
        with
        [
            R=bool,
            T0=boost::signals::detail::stored_group,
            T1=boost::signals::detail::stored_group,
            Compare=std::less<int>,
            Key=int,
            Functor=boost::signals::detail::group_bridge_compare<std::less<int>,int>,
            B=true,
            T=int
        ]
        boost\signals\signal_template.hpp(194) : while compiling class-template member function 'boost::signal1<R,T1,Combiner,Group,GroupCompare,SlotFunction>::signal1(const Combiner &,const GroupCompare &)'
        with
        [
            R=boost::detail::function_traits_helper<boost::add_pointer<void (int)>::type>::result_type,
            T1=boost::detail::function_traits_helper<boost::add_pointer<void (int)>::type>::arg1_type,
            Combiner=boost::last_value<void>,
            Group=int,
            GroupCompare=std::less<int>,
            SlotFunction=boost::function<void (int)>
        ]
       boost\signal.hpp(335) : see reference to class template instantiation 'boost::signal1<R,T1,Combiner,Group,GroupCompare,SlotFunction>' being compiled
        with
        [
            R=boost::detail::function_traits_helper<boost::add_pointer<void (int)>::type>::result_type,
            T1=boost::detail::function_traits_helper<boost::add_pointer<void (int)>::type>::arg1_type,
            Combiner=boost::last_value<void>,
            Group=int,
            GroupCompare=std::less<int>,
            SlotFunction=boost::function<void (int)>
        ]
  
     ProblemClass.h(12) : see reference to class template instantiation 'boost::signal<Signature>' being compiled
        with
        [
            Signature=void (int)
        ]


I would really like to use the signals library, but this is frustrating me. Any ideas? [Edited by - Valere on May 14, 2007 8:30:29 PM]

Share this post


Link to post
Share on other sites
Advertisement
After much trial and error, I found the problem. It turns out that this statement is the culprit.

#define new DEBUG_NEW

While a relatively common define in Visual studio produced apps, is incompatible with function objects. Marking this solved. Sorry for the trouble.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!