By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,445 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,445 IT Pros & Developers. It's quick & easy.

alias for variables obtained by inheritance

P: n/a
Hi everyone,

I wrote some code for a class but then I decided that I wanted to
inherit from this class. Well, it turns out that now I have to put
"this->" in front of all the member variables of the class that I'm
inheriting from in order to compile correctly. Is there another way to
do this? There has to be a way to define an alias command so I can
define it once and then use my original names.

Thank you,

a^2

Dec 26 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

aaragon wrote:
I wrote some code for a class but then I decided that I wanted to
inherit from this class. Well, it turns out that now I have to put
"this->" in front of all the member variables of the class that I'm
inheriting from in order to compile correctly. Is there another way to
do this? There has to be a way to define an alias command so I can
define it once and then use my original names.

Aaragon, you've posted many times before, so you know the drill. If
you want good responses to your question, you need to post the smallest
compilable piece of code that exhibits the problem you're describing.
Otherwise, we're just using our crystal balls to diagnose your problem,
and our crystal balls just aren't as accurate as we'd like.

Offhand, it sounds like you're inheriting from a template class, but
I'd need to see the code to be sure.

Best regards,

Tom

Dec 26 '06 #2

P: n/a

Thomas Tutone wrote:
aaragon wrote:
I wrote some code for a class but then I decided that I wanted to
inherit from this class. Well, it turns out that now I have to put
"this->" in front of all the member variables of the class that I'm
inheriting from in order to compile correctly. Is there another way to
do this? There has to be a way to define an alias command so I can
define it once and then use my original names.


Aaragon, you've posted many times before, so you know the drill. If
you want good responses to your question, you need to post the smallest
compilable piece of code that exhibits the problem you're describing.
Otherwise, we're just using our crystal balls to diagnose your problem,
and our crystal balls just aren't as accurate as we'd like.

Offhand, it sounds like you're inheriting from a template class, but
I'd need to see the code to be sure.

Best regards,

Tom
Thanks for replying Tom. The thing is that the code is huge. Now I have
to change the design and I run into this problem of renaming all the
member variables because for some reason the compiler doesn't recognize
that those variables were inherited. I'm gonna try to summarize the
code as follows:

template
<
typename class1
>
class classA
{
protected:

// statistics variables
class1 varClass1;
size_t var1;
size_t var2;
size_t var3;
};

template
<
typename class1
>
class classB : public classA<class1>
{
void statistics()
{
cout<<"class1 -"<<varClass1.print()<<endl;
cout<<"var1 = "<<var1<<endl;
cout<<"var2 = "<<var2<<endl;
cout<<"var3 = "<<var3<<endl;
}
};

I wrote this code because it shows the problem that I have right now.
The problem is that if I don't put the "this->" before the member
variables that were inherited (var1, var2, var3 and varClass1), the
compiler gives me a message as if those variables don't exist. Then, I
thought that it may be a way to set an alias for them. Any ideas?

Dec 26 '06 #3

P: n/a
aaragon wrote:
Thomas Tutone wrote:
aaragon wrote:
I wrote some code for a class but then I decided that I wanted to
inherit from this class. Well, it turns out that now I have to put
"this->" in front of all the member variables of the class that I'm
inheriting from in order to compile correctly. Is there another way to
do this? There has to be a way to define an alias command so I can
define it once and then use my original names.

Aaragon, you've posted many times before, so you know the drill. If
you want good responses to your question, you need to post the smallest
compilable piece of code that exhibits the problem you're describing.
Otherwise, we're just using our crystal balls to diagnose your problem,
and our crystal balls just aren't as accurate as we'd like.

Offhand, it sounds like you're inheriting from a template class, but
I'd need to see the code to be sure.

Best regards,

Tom

Thanks for replying Tom. The thing is that the code is huge. Now I have
to change the design and I run into this problem of renaming all the
member variables because for some reason the compiler doesn't recognize
that those variables were inherited. I'm gonna try to summarize the
code as follows:

template
<
typename class1
class classA
{
protected:

// statistics variables
class1 varClass1;
size_t var1;
size_t var2;
size_t var3;
};

template
<
typename class1
class classB : public classA<class1>
{
void statistics()
{
cout<<"class1 -"<<varClass1.print()<<endl;
cout<<"var1 = "<<var1<<endl;
cout<<"var2 = "<<var2<<endl;
cout<<"var3 = "<<var3<<endl;
}
};

I wrote this code because it shows the problem that I have right now.
The problem is that if I don't put the "this->" before the member
variables that were inherited (var1, var2, var3 and varClass1), the
compiler gives me a message as if those variables don't exist. Then, I
thought that it may be a way to set an alias for them. Any ideas?
Nice to know my crystal ball was working just fine.

This is an FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.19

Best regards,

Tom

Dec 27 '06 #4

P: n/a

Thomas Tutone wrote:
aaragon wrote:
Thomas Tutone wrote:
aaragon wrote:
>
I wrote some code for a class but then I decided that I wanted to
inherit from this class. Well, it turns out that now I have to put
"this->" in front of all the member variables of the class that I'm
inheriting from in order to compile correctly. Is there another way to
do this? There has to be a way to define an alias command so I can
define it once and then use my original names.
>
>
Aaragon, you've posted many times before, so you know the drill. If
you want good responses to your question, you need to post the smallest
compilable piece of code that exhibits the problem you're describing.
Otherwise, we're just using our crystal balls to diagnose your problem,
and our crystal balls just aren't as accurate as we'd like.
>
Offhand, it sounds like you're inheriting from a template class, but
I'd need to see the code to be sure.
>
Best regards,
>
Tom
Thanks for replying Tom. The thing is that the code is huge. Now I have
to change the design and I run into this problem of renaming all the
member variables because for some reason the compiler doesn't recognize
that those variables were inherited. I'm gonna try to summarize the
code as follows:

template
<
typename class1
>
class classA
{
protected:

// statistics variables
class1 varClass1;
size_t var1;
size_t var2;
size_t var3;
};

template
<
typename class1
>
class classB : public classA<class1>
{
void statistics()
{
cout<<"class1 -"<<varClass1.print()<<endl;
cout<<"var1 = "<<var1<<endl;
cout<<"var2 = "<<var2<<endl;
cout<<"var3 = "<<var3<<endl;
}
};

I wrote this code because it shows the problem that I have right now.
The problem is that if I don't put the "this->" before the member
variables that were inherited (var1, var2, var3 and varClass1), the
compiler gives me a message as if those variables don't exist. Then, I
thought that it may be a way to set an alias for them. Any ideas?

Nice to know my crystal ball was working just fine.

This is an FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.19

Best regards,

Tom
Thank you!! This is exactly what I was looking for.

Dec 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.