DEVELOP > c-Plus-Plus > How can I use a class name Rect when there is a function has the same name
| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
12 Feb 2007 05:11:29 PM |
| Object: |
How can I use a class name Rect when there is a function has the same name |
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.
.
|
|
| User: "Thomas J. Gritzan" |
|
| Title: Re: How can I use a class name Rect when there is a function hasthe same name |
12 Feb 2007 06:39:26 PM |
|
|
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
.
|
|
|
|
| User: "red floyd" |
|
| Title: Re: How can I use a class name Rect when there is a function hasthe same name |
12 Feb 2007 06:15:16 PM |
|
|
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.
.
|
|
|
|

|
Related Articles |
|
|