I have a problem. I need to pass a non-static data member in one class (class Disks, data member disks) to another class (ToH) to its static bool function, so I can test that value.
Here is my error:
: error C2597: illegal reference to non-static member 'Disks::disks'
My code:
#include "Disks.h" // include definition of class Disks
//constructor to initialize the data member
Disks::Disks(int enteredInteger)
{
setVariables(enteredInteger);
}
// set function to set the values for the data members
void Disks::setVariables(int enteredInteger)
{
disks = enteredInteger; // 3
choice = enteredInteger; // peg 3
}
void Disks::towers( int disks, int start, int end, int temp )
{
if ( disks == 1 )
{
cout << start << " --> " << end << endl;
}
else // recursion step
{
towers( disks-1, start, temp, end );
cout << start << " --> " << end << endl;
towers( disks-1, temp, end, start);
}
}
void Disks::transfer()
{
cout << "Instructions to move disks:";
cout << endl
<< "1) 1 --> 2" << endl
<< "2) 1 --> 3" << endl
<< "3) 2 --> 1" << endl
<< "4) 2 --> 3" << endl
<< "5) 3 --> 1" << endl
<< "6) 3 --> 2" << endl;
cout << endl;
switch(choice)
{
case 1:
towers( disks, 1, 2, 3 );
break;
case 2:
towers( disks, 1, 3, 2 );
break;
case 3:
towers( disks, 2, 1, 3 );
break;
case 4:
towers( disks, 2, 3, 1 );
break;
case 5:
towers( disks, 3, 1, 2 );
break;
case 6:
towers( disks, 3, 2, 1 );
break;
}
}
// test function in class ToH uses a test method to test the recursion
bool ToH::test()
{
bool answer;
if(Disks::disks == 1) // this is my problem / error
{
answer = true;
cout << "Function passed.";
}
else
{
answer = false;
cout << "Function failed.";
}
return answer;
}