Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Declaration of s specific type of method, outside the class-definition. How ? (http://www.go4expert.com/forums/declaration-s-specific-type-method-t4725/)

KimRaver 17Jun2007 17:04

Declaration of s specific type of method, outside the class-definition. How ?
 
How do i declare a method that returns a doublepointer to a subclass, outside the Class-definition ?

That is, as of now I have
Code:

Class House
{
    ...
    ...
    Class Room
    {
        ...
      }

      Room** myfunction(args)
    {
        Room **foo;
        ...
      return Room;
  }
}

I would like to be able to move the myfunction outside the class-definition as usual; according to
Code:

Room** House::myfunction(args)
{
    Room **foo
    ...
    return foo;
}

But the compiler complains.

How do you write the declarations when it is not some of the traditional return types as void, int, float etc. ?

DaWei 17Jun2007 18:16

Re: Declaration of s specific type of method, outside the class-definition. How ?
 
You return it the same way, whether you define it "inside" the class or "outside".

"The compiler complains" is a crappy explanation. Exactly what is your compiler's complaint? If I were your compiler, I'd complain, too. The first example has "return Room" while the second has "return foo". Why don't you give us a small, but complete, snippet that fails. I mean real code. The real stuff the compiler doesn't like. Include with it the real reason that it fails. Neither we nor the compiler are mind readers, and I can't see your monitor from my house.

KimRaver 17Jun2007 18:49

Re: Declaration of s specific type of method, outside the class-definition. How ?
 
Quote:

Originally Posted by DaWei
You return it the same way, whether you define it "inside" the class or "outside".

"The compiler complains" is a crappy explanation. Exactly what is your compiler's complaint? If I were your compiler, I'd complain, too. The first example has "return Room" while the second has "return foo". Why don't you give us a small, but complete, snippet that fails. I mean real code. The real stuff the compiler doesn't like. Include with it the real reason that it fails. Neither we nor the compiler are mind readers, and I can't see your monitor from my house.

Sorry, I couldn't edit the post. It should say "return foo;" in both examples. It is not the return-kommand thing that gives an error, I suppose.

It is how I should declare myfunction (the head) outside the Class by using ::. That is,
Room ** House :: myfunction (...) <<<----- This line is wrong I suppose, wont work.
{
Room **foo
...
return foo;
}

while normally if the function should return a int ** you can declare it as

int ** House :: other_function (...)
{ int **foo; ... return foo;}

Errors:
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2556: 'int **House::myfunction(void)' : overloaded function differs only by return type from 'House::Room **House::myfunction(void)'
see declaration of 'House::myfunction'
'House::myfunction' : redefinition; different basic types
see declaration of 'House::myfunction'


All times are GMT +5.5. The time now is 13:51.