Trouble with undefined references

Ok I'm getting these errors:


/tmp/ccNvtehj.o: In function `tool::tool()':
tool.cpp:(.text+0xf): undefined reference to `vtable for tool'
/tmp/ccNvtehj.o: In function `tool::tool(tool const&)':
tool.cpp:(.text+0x3b): undefined reference to `vtable for tool'
/tmp/cc4j4M7t.o:(.rodata._ZTI4rock[typeinfo for rock]+0x10): undefined reference to `typeinfo for tool'
/tmp/cclhq2Zz.o:(.rodata._ZTI5paper[typeinfo for paper]+0x10): undefined reference to `typeinfo for tool'
/tmp/cceU2w5F.o:(.rodata._ZTI8scissors[typeinfo for scissors]+0x10): undefined reference to `typeinfo for tool'
collect2: ld returned 1 exit status


Here's my codes:
tool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef TOOL_H
#define TOOL_H

class tool
{
protected:
    int strength;
    char type;
    
public:
    tool();
    tool(tool const &);
    void set_strength(int);
    virtual bool fight(tool *);
    char get_type();
    int get_strength();
};

#endif 

tool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "./tool.h"
#include <iostream>

tool::tool()
{
    strength = 1;
    type = NULL;
}

tool::tool(tool const&)
{
    
}

/*virtual bool tool::fight(<#tool *#>)
{
    return;
}*/

char tool::get_type()
{
    return type;
}

int tool::get_strength()
{
    return strength;
}


Can anyone help me out with what exactly these errors mean and if at all possible, could I get a bit of guidance in fixing the errors. I'd be ever so grateful. :)

Thank you.
Last edited on
"undefined reference" means the compiler can't find the definition of a function. I think the function it complains about is the fight function but you should also define the set_strength function.
Topic archived. No new replies allowed.