Reputation: 1010
I have some problems with sending structure to function:
Here is my main.cpp file:
#include "stdafx.h"
#include "vehicles.h"
#include <iostream>
#include "tools.h"
#include <time.h>
#include <vector>
using MAP_GRID = vector<vector<string>>;
using namespace std;
void print_terrain(MAP_GRID);
void set_position(MAP_GRID &, int, int, position &, string);
void random_position(MAP_GRID &, int, string);
MAP_GRID create_terrain();
MAP_GRID MAP = create_terrain();
int _tmain(int argc, _TCHAR* argv[])
{
tanks t34(12, 0.5, 21,6);
srand(time(NULL));
set_position(MAP, 5, 5, player,"[x]");
//[...]
}
Here is another file, with definition of this function:
#include "stdafx.h"
#include <iostream>
#include <vector>
#define MIN_SIZE 6
#define MAX_SIZE 15
using std::vector;
using std::string;
using MAP_GRID = vector<vector<string>>;
int global_size;
struct position{
vector<int> x;
vector<int> y;
};
void set_position(MAP_GRID &MAP, int x, int y, position &pos, string object)
{
if (x <= MAP.size() || y <= MAP.size())
if (MAP[x][y] != "[ ]")
std::cout << "\nPosition is occupied" << std::endl;
else
{
MAP[x][y] = object;
pos.x.push_back(x);
pos.y.push_back(y);
}
else
std::cout << "\Choose correct position" << std::endl;
}
This structure have to hold coordinate of some point (numbers of these points depends of object).
Upvotes: 0
Views: 104
Reputation: 385144
This has nothing at all to do with vectors (as you'd have discovered, had you constructed a minimal testcase during your many days of painstakingly debugging this problem).
You have to at least declare identifiers in every translation unit you want to use them in, before you use them.
You have not done that, so the compilation of main.cpp will fail because, indeed, it has no idea what position
is supposed to be. player
is, likewise, a complete mystery.
Typically we define types in "header files", making for easy inclusion of these definitions across multiple translation units. In this case, you can at least get away with a forward declaration of position
.
Upvotes: 1