compiler error: 'array1' is not a type
This error message makes no sense; 'array1' is an array name.
The code looks good to me. Please tell me what I am missing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
char array1[2] = { 'a', 'b' };
char array2[2] = { 'x', 'y' };
class Matrix
{
protected:
char * array;
public:
Matrix(char * arrayT) { array = arrayT; };
};
class SplitKeyboard
{
public: // SplitKeyboard is composed of two matrices
Matrix matrix1(array1); //error: 'array1' is not a type Matrix matrix1(array1);
Matrix matrix2(array2); //error: 'array2' is not a type Matrix matrix2(array2);
};
SplitKeyboard keyboard;
int main()
{
return 0;
}
|
error: 'array1' is not a type Matrix matrix1(array1);
error: 'array2' is not a type Matrix matrix2(array2); |
You're missing the type for your parameter. What type of variable is array1?
The error message says that array1 is not a TYPE. You cannot put a name, you need to put a TYPE
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class SplitKeyboard
{
public: // SplitKeyboard is composed of two matrices
Matrix matrix1;
Matrix matrix2;
SplitKeyboard(char*, char*);
};
SplitKeyboard::SplitKeyboard(char* a1, char* a2)
{
//initialize matrix 1 and matrix2
}
|
You could use an empty constructor instead, if array1 and array2 are global, but use of global variables is usually a sign of bad programming
Thanks jlb and ats15. Now I see the light. This is what I was trying to do (this compiles):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
char array1[2] = { 'a', 'b' };
char array2[2] = { 'x', 'y' };
class Matrix
{
protected:
char * array;
public:
Matrix(char * arrayT) { array = arrayT; };
};
class SplitKeyboard
{
public: // SplitKeyboard is composed of two matrices
Matrix matrix1;
Matrix matrix2;
SplitKeyboard(): matrix1(array1), matrix2(array2) { };
};
SplitKeyboard keyboard;
int main()
{
return 0;
}
|
Last edited on
Topic archived. No new replies allowed.