linker command failed with exit code 1 | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

linker command failed with exit code 1

I have been creating a Map class for creating allocated 2d Array. When I tried to Complier the file there is linker command failed to show up. Can anyone could help me figure out? here is my Cpp file #include<iostream> #include "Map.hpp" Map::Map() { // arr=nullptr; Map::setMapWidth(0); Map::setMapHeight(0); } Map::Map(int y,int x) { mapHeight=y; mapWidth=x; arr = new int*[y]; for(int i = 0; i < y; ++i) { arr[i] = new int[x]; } } Map::~Map() { for(int i = 0; i < mapHeight; ++i) { delete [] arr[i]; } delete [] arr; } Here is my Header file #ifndef Map_hpp #define Map_hpp #include<string> #include<stdio.h> class Map{ private: int mapWidth; int mapHeight; int **arr; public: Map(); Map(int width,int height); ~Map(); void setMapWidth(int width); void setMapHeight(int height); int getMapWidth(){return mapWidth;} int getMapHeight(){return mapHeight;} }; #endif /* Map_hpp */

20th Nov 2018, 6:16 AM
Jimmy Chen
Jimmy Chen  - avatar
2 Antworten
+ 4
These two members haven't been defined in the implementation file void setMapWidth(int width); void setMapHeight(int height); They are called from the default constructor and the compiler can not find any definition of them.
20th Nov 2018, 7:19 AM
Babak
Babak - avatar
+ 1
thank you for your help!
20th Nov 2018, 7:37 AM
Jimmy Chen
Jimmy Chen  - avatar