How can I use a class name Rect when there is a function has the same name

Discussion in 'C++' started by yinglcs@gmail.com, Feb 12, 2007.

  1. Guest

    Hi,

    I have a class called 'A', and it has a method called 'Rect(int x, int
    y, int w, int h)'

    And I have another class called 'Rect'.

    When I called 'Rect* in other method of A, I get this compiler error:
    void A::aMethod() {
    Rect* lastRect;
    // ...
    }

    error: 'lastRect' was not declared in this scope

    I think the compiler confuses the class Rect with the method Rect.

    Can you please tell me if there is a work around for my problem? I
    cant' rename the class Rect or the method 'Rect' in class A since they
    are both legacy code.

    Thank you for any idea.
     
    , Feb 12, 2007
    #1
    1. Advertising

  2. red floyd Guest

    Re: How can I use a class name Rect when there is a function hasthe same name

    wrote:
    > Hi,
    >
    > I have a class called 'A', and it has a method called 'Rect(int x, int
    > y, int w, int h)'
    >
    > And I have another class called 'Rect'.
    >
    > When I called 'Rect* in other method of A, I get this compiler error:
    > void A::aMethod() {
    > Rect* lastRect;
    > // ...
    > }
    >
    > error: 'lastRect' was not declared in this scope
    >
    > I think the compiler confuses the class Rect with the method Rect.
    >
    > Can you please tell me if there is a work around for my problem? I
    > cant' rename the class Rect or the method 'Rect' in class A since they
    > are both legacy code.
    >


    Put it in a namespace. Otherwise, you're pretty much SOL.
     
    red floyd, Feb 13, 2007
    #2
    1. Advertising

  3. Re: How can I use a class name Rect when there is a function hasthe same name

    schrieb:
    > Hi,
    >
    > I have a class called 'A', and it has a method called 'Rect(int x, int
    > y, int w, int h)'
    >
    > And I have another class called 'Rect'.
    >
    > When I called 'Rect* in other method of A, I get this compiler error:
    > void A::aMethod() {
    > Rect* lastRect;


    Try this:

    ::Rect* lastRect;

    > // ...
    > }
    >
    > error: 'lastRect' was not declared in this scope
    >
    > I think the compiler confuses the class Rect with the method Rect.


    --
    Thomas
    http://www.netmeister.org/news/learn2quote.html
     
    Thomas J. Gritzan, Feb 13, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bunty

    RECt Structure Problem

    bunty, Jul 6, 2006, in forum: C++
    Replies:
    9
    Views:
    435
    Jerry Coffin
    Jul 14, 2006
  2. globalrev

    pygame: rect moveto?

    globalrev, May 3, 2008, in forum: Python
    Replies:
    1
    Views:
    346
    Marc 'BlackJack' Rintsch
    May 3, 2008
  3. Chris Riesbeck

    getting computed clip rect

    Chris Riesbeck, Jul 15, 2008, in forum: Javascript
    Replies:
    31
    Views:
    365
    Laurent vilday
    Jul 16, 2008
  4. Scott Siegler

    pygame.Rect question

    Scott Siegler, Apr 9, 2012, in forum: Python
    Replies:
    1
    Views:
    323
    Peter Pearson
    Apr 9, 2012
  5. Alex Gardner

    Collision of Two Rect

    Alex Gardner, May 3, 2013, in forum: Python
    Replies:
    3
    Views:
    129
    Ian Kelly
    May 6, 2013
Loading...

Share This Page