Using non inherited operators

im having a slight brain fart here on how to call an overloaded operator from an inherited class. Basically what im trying to do is use my overloaded assignment operator from a base class to create the assignment operator in my inherited class.

This code probably has other issues but im only concerned with the assignment operator at this time.

Base class assignment operator:

StringBetter & operator=(const char *);

how im trying to implement it in the inherited class:
Header file decleration:

Sourceline &operator=(const char *);

Implementation:

1
2
3
4
Sourceline Sourceline :: &operator=(const char *);
{
     return StringBetter:: &operator=(const char *);
}


Here are the error messages i am receiving:
7 J:\School\Programming\progs\Sourceline\sourceline.cpp expected unqualified-id before '&' token
7 J:\School\Programming\progs\Sourceline\sourceline.cpp expected init-declarator before '&' token
7 J:\School\Programming\progs\Sourceline\sourceline.cpp expected `,' or `;' before '&' token
8 J:\School\Programming\progs\Sourceline\sourceline.cpp expected unqualified-id before '{' token
8 J:\School\Programming\progs\Sourceline\sourceline.cpp expected `,' or `;' before '{' token

I could be mashing some things together that just dont work and not be realizing it but im pretty sure i can do this because its the same idea as cumulative multiplication i.e.( 2*adt as apposed to adt*2) and using the one overloaded multiplication operator for both situations.

i hope this makes sense....
What is that & doing there? On line 1 I imagine it is supposed to be part of the return value, but I think it needs to be deleted on line 3. Have you ever used references before...?
lol yah i have used them before im just having a serious retard moment... I up-dated my code now it looks a little better:

1
2
3
4
Sourceline &Sourceline :: operator=(const char *temp)
{
     return StringBetter:: operator=(temp);
}


J:\School\Programming\progs\Sourceline\sourceline.cpp In member function `Sourceline& Sourceline::operator=(const char*)':
9 J:\School\Programming\progs\Sourceline\sourceline.cpp invalid initialization of reference of type 'Sourceline&' from expression of type 'StringBetter'

im still learning about inheritance, so i dunno i might still be doing a bunch of stuff rong
well i figured out why i was getting errors i just needed to slow down take a look at what i was actually doing. Thanks for the help Zhuge

working code:
1
2
3
4
5
Sourceline &Sourceline :: operator=(const char *temp)
{
     StringBetter:: operator=(temp);
     return *this;
}


Thanks again Zhuge
Topic archived. No new replies allowed.