Hi,
This is some code in the first class:
Slot is another class i defined of which i want 2 objects.
Note that this is an array of pointers.
For some reason, which is unknown to me, slotArray[i] is an object instead of what i think it should be a pointer. So my compiler keeps asking me to change the -> to a . and also i get an error converting from a Slot to a Slot*. However i really do need a Slot * and not a Slot.
I'd like to know:
1. Why slotArray[i] is an object and not a pointer.
2. How to solve the first problem(ofcours e)
3. How to solve the 2nd problem
Thanks in advance,
BSCode266
This is some code in the first class:
Code:
//the array of pointers
Slot *slots[2];
//the get method for the previous array
//The first error occurs here: error C2440: 'return' : cannot convert from 'Slot *[2]' to 'Slot *'
Slot* ForgeScreen::getSlots(){
return slots;
}
Note that this is an array of pointers.
Code:
//This method has to return a pointer to a Slot.
Slot* Controller::checkMousePosition(int x, int y){
//slotArray is the pointer which will point to the array we are gonna get from the previous class.
Slot *slotArray;
if(inventory->getDraw()){
if( ( x > inventory->getX() ) && ( x < inventory->getX() + inventory->getW()) && ( y > inventory->getY()) && ( y < inventory->getY() + inventory->getH()) ){
//Here we get the array and make the slotArray point to it.
slotArray = inventory->getSlots();
}
}
if(forgeScreen->getDraw()){
if( ( x > forgeScreen->getX() ) && ( x < forgeScreen->getX() + forgeScreen->getW()) &&
( y > forgeScreen->getY()) && ( y < forgeScreen->getY() + forgeScreen->getH()) ){
//Or here we get the array and make the slotArray point to it.
slotArray = forgeScreen->getSlots();
}
}
//Its all about this part.
if(slotArray != NULL){
for(int i = 0; i < 2; i++){
if( ( x > slotArray[i]->getX() ) && ( x < slotArray[i]->getX() + slotArray[i]->getW()) &&
( y > slotArray[i]->getY()) && ( y < slotArray[i]->getY() + slotArray[i]->getH()) ){
//The second error occurs here: error C2440: 'return' : cannot convert from 'Slot' to 'Slot *'
return slotArray[i];
}
}
}
return NULL;
}
I'd like to know:
1. Why slotArray[i] is an object and not a pointer.
2. How to solve the first problem(ofcours e)
3. How to solve the 2nd problem
Thanks in advance,
BSCode266
Comment