English 中文(简体)
C++中“未明确”的术语
原标题:About "undefined refence to" in C++
  • 时间:2011-10-16 01:51:21
  •  标签:
  • c++

=

我在C++中有一个“未明确提及”的问题。

这里,我有:

#include "HelloWorldAgent/helloworldagent.hh"

int main()
{
   HelloWorldAgent agent;
   agent.run();
}

在另一个C++档案中,下一个编码是:

#ifndef _HELLOWORLDAGENT_HH_
#define _HELLOWORLDAGENT_HH_

#include "../../HumanoidAgent/humanoidagent.hh"

/**
 *  A friendly robot
 */
class HelloWorldAgent : public bats::HumanoidAgent
{
/**
 * Initialize agent
*
* Called a single time when starting up the agent. Put all your initialization stuff  
here.
*/
virtual void init();

/**
* Think cycle
*
* Called at each cycle after a message from the server is received and parsed. 
Put all your thinking and acting stuff here.
*/
virtual void think();

public:

/**
*  The Constructor
*
*  Sets this agent s teamname to "Hello". Consider putting initialization stuff in 
init() instead of here.
*/
HelloWorldAgent()
: HumanoidAgent(std::string("Hello"))
{
}

};

#endif

我试图将其编成第2版。

g++-I/usr/include/eigen - I /usr/include/sigc++-2.0 - I /usr/lib/sigc++-2.0/include helloworld.cc

给我下一个错误:

In file included from /usr/lib/gcc/i486-slackware-linux/4.5.2/../../../../include/c++/4.5.2/ext/hash_map:60:0, from HelloWorldAgent/../../HumanoidAgent/../WorldModel/../Hashclasses/hashclasses.hh:25, from HelloWorldAgent/../../HumanoidAgent/../WorldModel/worldmodel.hh:54, from HelloWorldAgent/../../HumanoidAgent/humanoidagent.hh:46, from HelloWorldAgent/helloworldagent.hh:44, from helloworld.cc:1: /usr/lib/gcc/i486-slackware-linux/4.5.2/../../../../include/c++/4.5.2/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. /tmp/cc1cjIEs.o: In function main : helloworld.cc:(.text+0x29): undefined reference tobats::HumanoidAgent::run() /tmp/cc1cjIEs.o: In function HelloWorldAgent::HelloWorldAgent() : helloworld.cc:(.text._ZN15HelloWorldAgentC2Ev[_ZN15HelloWorldAgentC5Ev]+0xfd): undefined reference tovtable for HelloWorldAgent /tmp/cc1cjIEs.o: In function HelloWorldAgent::~HelloWorldAgent() : helloworld.cc:(.text._ZN15HelloWorldAgentD2Ev[_ZN15HelloWorldAgentD5Ev]+0xb): undefined reference tovtable for HelloWorldAgent collect2: ld returned 1 exit status

我不知道可以做些什么,也许会说错了。 任何想法?

Thanks in advance. =

PS: No, it is not homework, it is just for fun =

最佳回答

您没有将虚拟功能的实施(定义)列入。 确保在其余(或使用<代码>-c)的同时将这些定义的任何文件通过到G++,以便及时汇编一份至.o文档,然后将这些定义与最后链接步骤联系起来)

问题回答

解决这一问题的最简单办法是将HelloWorldAgent类别宣布的方法的实际定义列入格++指挥线。 由于你看来唯一需要使用的方法是操作的,因此,你必须对该档案中某些地方加以界定。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签