i'm trying to pass a 2D char array into a function declared in a header file.
//Proj1Aux.h
#ifndef PROJ1AUX_H
#define PROJ1AUX_H
void makeBoard(char (*myBoard)[10], int boardSize);
void printBoard(char (*myBoard)[10], int boardSize);
#endif
I defined the functions as follows:
//Proj1Aux.cpp
#include <iostream>
#include "Proj1Aux.h"
using namespace std;
void makeBoard(char (*myBoard)[10], int boardSize)
{
//code
}
void printBoard(char (*myBoard)[10], int boardSize){
//code
}
And then in my main function in another .cpp file:
//Proj1.cpp
#include <iostream>
#include <cstdlib>
#include "Proj1Aux.cpp"
using namespace std;
int main(int argc, char* argv[]){
//code...
//more code...
char board[10][10];
makeBoard(board, boardSize);
printBoard(board, boardSize);
}
I'm a beginner at C++, and I dont have a firm grasp on pointers, or even header files. I tried passing in the 2D array without any pointers, but the compiler gave me an error:
invalid conversion from 'const char*' to 'char'
So i tried putting in the pointers as listed above, and I get the same error
What do I do? can anyone go through my code and tell me exactly what's wrong?
.cppfiles in other.cppfiles until you have a very, very solid understanding of header files. That's an advanced technique that will only get you into trouble for now.