vendredi 22 mai 2020

Main don't detect my function from header [duplicate]

when i compile this, ubuntu sends me this error:

/mnt/c/users/acer/Documents/GitHub/tarea1-c-bfs-grupo-4-tarea-1/main.cpp:18: undefined reference to `Map::Map(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

what's wrong with this code?

 //main.cpp
#include "Map.h"
int main(int argc, char* argv[])// xIn, yIn, xMeta, yMeta, nombre del mapa
{
    /*int xIn = atoi(argv[1]);
    int yIn = atoi(argv[2]);
    int xMeta = atoi(argv[3]);
    int yMeta = atoi(argv[4]);*/
    string fileName(argv[5]);

    std::cout << "cantidad datos ingresados:" << argc << "\n";
    std::cout << fileName << "\n";
    assert(argc == 6);        //revisa si la cantidad de datos es 6, x,y inicial, xy meta y el nombre del archivo

    Map map(fileName);
}
//Map.h
#include <queue>
#include <algorithm>
#include <iostream>
#include <chrono>
#include <string>
#include <fstream>

class Map
{
    private:
        char mapChars[100][100];
    public:
        Map();                              //TODO: constructs empty map
        Map(std::string fileName);          //TODO: constructs from data in a file
        ~Map();                             //TODO: destructor
        Map& operator = (const Map& rhs);   //TODO: assignment operator

        void print() const;     //TODO: prints map
        void print(std::vector<std::pair<int, int>>) const
        {
        }; //TODO: prints map and path 

        friend bool operator == (const Map& lhs, const Map& rhs); //declares global operator friend 
};
//map.cpp
#include "Map.h"
#include "ColorMap.h"

Map::Map(){}

void Map::Map(string fileName) const
{
    int width;
    int length;
    ifstream inFile;
    inFile.open(filename);
    if (!inFile) 
    {
        cerr << "Unable to open file datafile.txt";
        exit(1);   // call system to stop
    }
    inFile >> width;
    inFile >> length;
    for (int i = 0; i < length; i++)
    {
        for (int q = 0; q < width; q++)
        {
            mapChars[q][i]<<inFile;
        }
    }

    inFile.close();
}

Aucun commentaire:

Enregistrer un commentaire