1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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

Discussion in 'C' started by KimRaver, Jun 17, 2007.

  1. KimRaver

    KimRaver New Member

    Joined:
    Jun 17, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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. ?
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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.
     
    Last edited: Jun 17, 2007
  3. KimRaver

    KimRaver New Member

    Joined:
    Jun 17, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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'
     

Share This Page