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



 DEVELOP > c-Plus-Plus > How can I use a class name Rect when there is a function has the same name

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

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


  Page 1 of 1

1

 


Related Articles
How to avoid the use of copy constructor when using STL container function (push_back, etc.)
When debug, I how to out put the name of the function.
how to call a C++ function from a C file when provided with only compiled code
Undefined symbol in C++ template member function when put on vxWorks
Why program denies when my function is loaded ?
stack address is different when parameter is passed to function?
GCC -- Warning when a non-virtual function is overridden?
member function reference when extending an STL class
Compile error when use Boost::lambda::bind function
rand() function generates same value when instantiating objects
Segmentation fault when function ends...
what does const mean when it comes *after* the function definition
About the retrogression problem when passing a array variable into a function which takes a pointer as its argument.
Variable number of arguments when calling a DLL function
When exiting function scope, which occurs first...
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER