469,651 Members | 1,647 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,651 developers. It's quick & easy.

alias for variables obtained by inheritance

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
4 1657

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

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

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.

Similar topics

2 posts views Thread by Jim Schueler | last post: by
4 posts views Thread by mexican_equivalent | last post: by
7 posts views Thread by Hazz | last post: by
8 posts views Thread by mike | last post: by
4 posts views Thread by DaveM | last post: by
reply views Thread by Bakunin | last post: by
30 posts views Thread by Logos | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.