[ad_1]
I am trying to run this main.cpp file:
#include "../include/world.h"
#include "../include/robot.h"
int main(int argc, char** argv) {
char map[7][7] = {
{'1', '1', '1', '1', '1', '1', '1'},
{'1', '0', '0', '0', '0', '0', '1'},
{'1', '0', '0', '0', '0', '0', '1'},
{'1', '0', '0', '1', '1', '0', '1'},
{'1', '0', '0', '1', '1', '0', '1'},
{'1', '0', '0', '0', '0', '0', '1'},
{'1', '1', '1', '1', '1', '1', '1'},
};
World w(map);
w.addRobot(1, 1);
w.run();
}
This is world.cpp:
#include <iostream>
#include <thread>
#include <chrono>
#include "world.h"
World::World(char map[7][7]) {
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
map_[i][j] = map[i][j];
std::cout << map_[i][j] << std::endl;
}
}
}
bool World::addRobot(int row, int col) {
map_[row][col] = 'A';
return true;
}
void World::run() {
while (true) {
display();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
void World::display() {
// "Clear" screen
for (int i = 0; i < 20; i++){std::cout << std::endl;}
for (auto & i : map_) {
for (char j : i) {std::cout << j;}
std::cout << std::endl;
}
}
But this is the error:
/usr/bin/ld: /tmp/ccBztQoR.o: in function `main':
main.cpp:(.text+0xb1): undefined reference to `World::World(char (*) [7])'
/usr/bin/ld: main.cpp:(.text+0xc7): undefined reference to `World::addRobot(int, int)'
/usr/bin/ld: main.cpp:(.text+0xd3): undefined reference to `World::run()'
collect2: error: ld returned 1 exit status
Everything is accurately defined from what I can see. Where am I going wrong? How am I not defining it?
[ad_2]