开发者

unresolved external symbol "public: void __thiscall..."

I'm using boost::function to enable the passing of a function to a Button constructor so it holds that function. Calling it whenever it is activated.

typedef boost::function< void() > Action;

In my TitleState I've constructed a Button like this.

  m_play( 
    ButtonAction, // This is where I pass a function to Button's Action argument
    sf::Vector2f( 500, 400 ), 
    sf::IntRect( 500, 400, 700, 500 ) 
  )

where ButtonAction is a static void function privately held in TitleState's header, defined in the implementation file as simply outputting to the console via std::cout (just as a test for whether it is working).

In my code, if the mouse clicks a button in TitleState's HandleEvents function, the program calls that button's Activate function which looks like this.

void Button::Activate() const {
  m_action(); // m_action is the Action member that holds the ButtonAction I passed earlier
}

The problem is that, when the program tries to link I get this error....

unresolved external symbol "public: void __thiscall Button::Activate(void)" (?Activate@Button@@QAEXXZ) referenced in function "public: virtual void __thiscall TitleState::HandleEvents(void)" (?HandleEvents@TitleState@@UAEXXZ)

I'm not sure what the problem is besides that the linker can't find the definition of the function. Everything is #included or declared properly. Any assistance is appreciated. Thanks.

P.S. When I used the BoostPro installer, I only installed the single-threaded stu开发者_StackOverflowff and none of the multi-threaded stuff. Could this be a reason why it isn't working? I read that linker problems can occur when libraries are linking in different ways. If this could be an issue, I'll add that I'm also using the SFML library.


Add the library option when you are linking your program:

g++:

g++ -L/your/library/path -lyour_library_name

vc++:

  • using boost with vc++


I'm not sure what the problem is. Everything is #included or declared properly. Any assistance is appreciated. Thanks.

That just means the compiler finds the declaration. But the linker has to find the definitions of the symbols. (See this SO question for what's the difference between a declaration and a definition.) You need to provide it with the library. If you're using GCC, follow Phong's advice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜