I'm doing a part to a project where I'm making a weapon class and a test program. The weapon class has to have three private data members: two integers (hit_chance and stamina_required) and a string for the weapon type. There is suppossed to be two public member functions: a display function which prints out the private data members and a constructor (which takes 3 arguments to initialize the private data). My teacher wants us to split the Weapon class into Weapon.h and Weapon.cpp and to put the main() function in another file named assignment10.cpp
Then I'm writing a makefile to build the program.
Heres what I have for the Weapon.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include<string>
2 usingnamespace std;
3
4
5 class Weapon {
6 private:
7 int hit_chance;
8 int stamina_required;
9 string weapon;
10
11
12 public:
13 void display(void);
14 Weapon(string weapon, int hit, int stamina);
15
16 };
17
I did what you said, still getting these errors:
when I compile Weapon.cpp
1 2 3 4
Weapon.cpp: In member function 'void Weapon::display()':
Weapon.cpp:12: error: 'hit' was not declared in this scope
Weapon.cpp:13: error: 'stamina' was not declared in this scope
When I try to compile assignment10.cpp:
1 2 3 4
/tmp/ccRiQHkt.o: In function `main':
assignment10.cpp:(.text+0x45): undefined reference to `Weapon::Weapon(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int)'
assignment10.cpp:(.text+0x84): undefined reference to `Weapon::display()'
collect2: ld returned 1 exit status
/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../lib64/crt1.o: In function `_start':
/glibc-tmp-4211a76efa4c5de6d46269f47808acd6/glibc-2.11.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
collect2: ld returned 1 exit status
1 2 3 4
/tmp/cc2w47FN.o: In function `main':
assignment10.cpp:(.text+0x45): undefined reference to `Weapon::Weapon(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int)'
assignment10.cpp:(.text+0x84): undefined reference to `Weapon::display()'
collect2: ld returned 1 exit status