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

Y

yinglcs

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.
 
R

red floyd

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.
 
T

Thomas J. Gritzan

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;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top