I've seen this problem a few times and I've tried what they've done. I am still not passing my Array correctly.
I'm all templated up because of last files I have used for this program (Not in the code). If that could have something to do with it let me know.
This is the base code I was working with. My Edited code became to tangled I couldn't work with it. So if something is a tiny error it's because it was rebuild quickly and haphazardly so I apologize in advance if there are any of those problems.
template <class T>
class Boggle
{
public:
Boggle(void);
~Boggle(void);
int ** MyBoard;
int size;
int Rows;
int Cols;
void SizeBoard();
void PrintBoard();
};
template <class T>
Boggle<T>::Boggle(void)
{
Size = 0;
Rows = 0;
Cols = 0;
}
template <class T>
Boggle<T>::~Boggle(void)
{
}
template <class T>
void Boggle<T>::SizeBoard()
{
int size;
Rows = 0;
cout << "Enter your Boggle Board Size. (Please input one number)."<<endl;
cin >> size;
MyBoard = new int*[size];
for (Rows=0; Rows<size; Rows++)
{
MyBoard[Rows] = new int[size];
}
for(Rows=0; Rows<size; Rows++)
{
for(int Cols=0; Cols<size; Cols++)
{
MyBoard[Rows][Cols] = Cols;
}
}
}
template <class T>
void Boggle<T>::PrintBoard()
{
for (int Rows = 0; Rows < size; Rows++)
{
for (int Cols = 0; Cols < size; Cols++)
cout << MyBoard[Rows][Cols] << " ";
cout << endl;
}
}
When I Print my Array nothing ever comes out. I used a couple different functions with dummy cout codes to see if it's passing and I've tried alot of different things. I've definitely spent alot of time working on this.
The Main simply has the functions running in it for testing.
When I put these both in the main they work just fine. Which leaves me to believe it's a passing error in my class.
Normally this would be an easy problem however I don't normally Template or work with 2D arrays so I'm kind of out of my element.