Answer the question
In order to leave comments, you need to log in
How to use namespace in header?
#include <iostream>
#include <vector>
#include <string>
#include "input.h"
int main()
{
setlocale(0, "");
input::do_input();
const uint8_t m = input::m, n = input::n;
return 0;
}
namespace input
{
void do_input();
extern uint8_t m;
extern uint8_t n;
extern std::vector<std::vector<bool>> field;
}
#include <iostream>
#include <vector>
#include <string>
using std::cout, std::cin;
using std::string, std::vector;
string buf;
uint8_t real_m, real_n;
uint8_t m, n;
vector<vector<bool>> field(m, vector<bool>(n));
void read_unuseful_line()
{
for (uint8_t i = 0; i < n; i++)
{
cin >> buf;
}
}
void do_input()
{
cin >> buf;
real_m = stoi(buf);
m = real_m - 2;
cin >> buf;
real_n = stoi(buf);
n = real_n - 2;
read_unuseful_line();
for (uint8_t i = 0; i < m; i++)
{
cin >> buf;
for (uint8_t j = 0; j < n; j++)
{
cin >> buf;
field[i][j] = stoi(buf);
}
cin >> buf;
}
read_unuseful_line();
for (auto row : field)
{
for (auto col : row)
{
cout << col << ' ';
}
cout << '\n';
}
}
c++ solution.cpp input.cpp -static
undefined reference to `input::do_input()
undefined reference to `input::m'
undefined reference to `input::n'
collect2.exe: error: ld returned 1 exit status
Answer the question
In order to leave comments, you need to log in
Wrap all code in input.cpp in a namespace input {}
namespace appends the namespace to the characters in the file object, but because If you have definitions in input.cpp not included in the namespace, then in the object file these symbols will be without adding the namespace, and therefore undefined reference.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question