views:

312

answers:

4

I have 1 compiler error. It is from this line in my code:

cout << myClass->Get_Type().discription; 

Where as Get_Type() is:

void Tile::Get_Type() {  
    return &myStruct;  
}

I'm not quite sure what I am doing wrong. Or what for that matter could be going wrong.

A: 

You are trying to return an object from a function which is defined as having no return type.

What should Get_Type be returning? It looks like you are trying to return an address to myStruct. If this is intended, you need your function definition to look like so:

TypeOfMyStruct* Tile::Get_Type() {
return &myStruct;
}

Replace "TypeOfMyStruct" with the actual type of myStruct.

If you don't want anything returned, then just remove the return &myStruct; line and that will fix your problem. However I suspect this is not the case.

Polaris878
+7  A: 

A function with a return type of void cannot return anything (that's what the void means: the function does not return anything). You are trying to return something (the address of myStruct).

You either need to return nothing (i.e. change your return to just be return; or remove it entirely) or change the return type of the function from void to a pointer to whatever the type of myStruct is.

James McNellis
+1  A: 

Get_Type returns void. So it can't be a structure with an element named discription. Or description.

You need, instead

TypeOfMyStruct * Tile::Get_Type() { ... }

And then you need:

foo->GetType()->description

because that's a pointer you want to return, not a reference.

bmargulies
+2  A: 

Your Get_Type() method has return type void whereas it should have the return type of myStruct.

If your struct is declared like this:

struct S {
  char* description;
}

your Get_Type should return a pointer of type S:

S* Tile::Get_Type(){
  return &myStruct;
}

assuming that myStruct is declared as:

S myStruct;

in the class declaration.

MKroehnert
You can format your code by indenting it 4 spaces or selecting it and clicking the `010` button... There is also inline markup etc., see the editing help for more.
Georg Fritzsche
Thanks, I knew it was there but the javascript creating the edit buttons was blocked before.
MKroehnert