Sign in to follow this  

using the same variable name twice in C++

This topic is 4203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You don't actually have two variables of the same name in that snippet. You have a variable B::name and a local variable (arg to function) called name. The exact same construct is possible in C++. The reason you got an error is because you tried to compile Java code with a C++ compiler.

You could do this:

class B
{
public:
char *name;

void SetName(char *name) { this->name = name; }
};






Share this post


Link to post
Share on other sites

This topic is 4203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this