As the title states...
Printable View
As the title states...
Code:int MyVariable;
class MyClass
{
public:
int MyVariable;
void MyFunction(int MyVariable);
};
void MyClass::MyFunction(int MyVariable)
{
MyVariable = 3; //Access the argument variable
::MyVariable = 12; //Access the global variable
this->MyVariable = 567; //Access the local variable
}
Not what i mean
Its a funtion not a variable that holds the same name as a
global variable and the compiler doesnt aprove it
You can't have two identifiers with the same name, wether they be variables or functions. Use another name (like put an i in front of the variable if it's an integer).Quote:
Error: param.cpp(7,2):Multiple declaration for 'Var'
You can do this (i think this is what you mean)
I think you are doing this:Code:
int some_number(void) {
return 10;
}
class myClass {
protected:
int some_number;
public:
void set(int);
};
void myClass :: set(int some_number) {
this->some_number = some_number;
}
And that is illegal. However, you can always use namespaces to do this.Code:int free;
void free(void *) {
....
}
Code:namespace first {
int free;
}
namespace second {
void free(void *) { }
}
int main(void) {
using namespace first;
free = 10;
void *someptr;
for(int i = 0; i < free; i++) {
using namespace second;
free(someptr);
}
}