Board index » delphi » Error: Operator 'operator' not implemented in type 'type'...

Error: Operator 'operator' not implemented in type 'type'...

Hi, all.
I use C++ Builder, but the error I got is not connected to any specific
compiler. It deals with C++.
I have a class with two operators but during compiling an error is occured:
Operator 'operator' not implemented in type 'type' for arguments of type
'type'.
What is the matter?
My code:
class Counter
{
public:
    Counter();
    Counter( int initialValue );
    ~Counter() {}
    Counter operator+( const Counter & );
    const Counter operator++( int );
    int GetitsVal() const { return itsVal; }
private:
    int itsVal;

Quote
};

Counter::Counter():
itsVal( 0 )
{}

Counter::Counter( int initialValue ):
itsVal( initialValue )
{}

Counter Counter::operator+( const Counter &rhs )
{
    return Counter( itsVal + rhs.GetitsVal() );

Quote
}

const Counter Counter::operator++( int )
{
    counter temp( *this );
    ++itsVal;
    return temp;

Quote
}

#pragma argused

int main( int argc, char* argv[] )
{
    Counter varOne( 2 ), varTwo;
    varTwo = varOne++ + varOne++;    // in this statement there is the error
// and so on...

 

Re:Error: Operator 'operator' not implemented in type 'type'...


Quote
>     varTwo = varOne++ + varOne++;    // in this statement there is the

error

Your operator++ takes an integer arguement, but here you do not supply one.
If you want to use this unary form, supply the missing arguement:

const Counter operator++( int incr=1 );

and

const Counter Counter::operator++( int incr)
{
    counter temp( *this );
    itsVal += incr;
    return temp;

Quote
}

Regards,
Bruce

Re:Error: Operator 'operator' not implemented in type 'type'...


Sorry but my question about C++ (I think about ANSI C++) not about compiler
implementation. As for me there is no difference where to write letter. I
also have Borland C++ 5.02.
I'd like to get answer about my question not about user group.

With best regards, Grigoriev Vladimir.

Andrue Cope <not.a.va...@email.address.sorry> ??? a
????:VA.00001cf2.06626...@email.address.sorry...

Quote
> Vladimir Grigoriev,

> > I use C++ Builder, but the error I got is not connected to any specific
> > compiler.

> It could be. Compilers are designed to implement a standard and that
> standard changes over time. In addition different compilers have
> different bugs and different deficiencies. This section is for a compiler
> that was last updated five years ago and is basically legacy support for
> the few people who for one reason or another still have to use that tool.

> I can't see why someone using the current compiler would even want to
> post a question here.

> If you are using C++ Builder then you should post to the CPPBUILDER
> sections. Not only does this ensure that you get answers that are
> tailored to your compiler it also increases the chance of getting a
> response by the simple fact that there are more Builder users to answer.

>   .CPPBUILDER.LANGUAGE.CPP

> Is a better place to ask.
> --
> Andrue Cope
> [Bicester, UK]

Re:Error: Operator 'operator' not implemented in type 'type'...


Vladimir Grigoriev,

Quote
> I use C++ Builder, but the error I got is not connected to any specific
> compiler.

It could be. Compilers are designed to implement a standard and that
standard changes over time. In addition different compilers have
different bugs and different deficiencies. This section is for a compiler
that was last updated five years ago and is basically legacy support for
the few people who for one reason or another still have to use that tool.

I can't see why someone using the current compiler would even want to
post a question here.

If you are using C++ Builder then you should post to the CPPBUILDER
sections. Not only does this ensure that you get answers that are
tailored to your compiler it also increases the chance of getting a
response by the simple fact that there are more Builder users to answer.

  .CPPBUILDER.LANGUAGE.CPP

Is a better place to ask.
--
Andrue Cope
[Bicester, UK]

Re:Error: Operator 'operator' not implemented in type 'type'...


Thanks Bruce.
The operator ++ has no error. You can use it alone for example varTwo =
varOne++;.
I take this code from the book "Teach Yourself C++ in 21 days" of Jesse
Liberty.
But than you use it with operator + ( i.e. when you use two operators in one
assignment statement as I described ) the error is occured. What is the
matter?

Vladimir Grigoriev.

Bruce Salzman <br...@nospam.org> D???
???Y??:3ecb80a...@newsgroups.borland.com...

Quote
> >     varTwo = varOne++ + varOne++;    // in this statement there is the
> error

> Your operator++ takes an integer arguement, but here you do not supply
one.
> If you want to use this unary form, supply the missing arguement:

> const Counter operator++( int incr=1 );

> and

> const Counter Counter::operator++( int incr)
> {
>     counter temp( *this );
>     itsVal += incr;
>     return temp;
> }

> Regards,
> Bruce

Re:Error: Operator 'operator' not implemented in type 'type'...


Quote
"Vladimir Grigoriev" <Vlad.Mos...@mail.ru> wrote in message

news:3ecb8359$1@newsgroups.borland.com...

Quote
> Thanks Bruce.
> The operator ++ has no error. You can use it alone for example varTwo =
> varOne++;.
> I take this code from the book "Teach Yourself C++ in 21 days" of Jesse
> Liberty.
> But than you use it with operator + ( i.e. when you use two operators in
one
> assignment statement as I described ) the error is occured. What is the
> matter?

That'll teach me to post an answer while still drinking my first cup of
coffee...

delcare your operator+ like this:

friend const Counter operator+(const Counter &lhs, const Counter &rhs);

and its implementation:

 const Counter operator+(const Counter &lhs, const Counter &rhs)
 {
    return Counter(lhs.itsVal + rhs.itsVal);
 }

BTW, in your example the line:

    varTwo = varOne++ + varOne++;

is not well defined. There is no "sequence point" between the increment
operators on the varOne object. This makes the result undefined and compiler
dependent...

HTH,
Bruce

Re:Error: Operator 'operator' not implemented in type 'type'...


Thank you.
I will use your advice than I will read all materials till the chapter
"friend functions". Perhaps new questions will be born at that time.

With best regards. Vladimir Grigoriev.

Bruce Salzman <br...@nospam.org> D???
???Y??:3ecb8bf...@newsgroups.borland.com...

Quote

> "Vladimir Grigoriev" <Vlad.Mos...@mail.ru> wrote in message
> news:3ecb8359$1@newsgroups.borland.com...
> > Thanks Bruce.
> > The operator ++ has no error. You can use it alone for example varTwo =
> > varOne++;.
> > I take this code from the book "Teach Yourself C++ in 21 days" of Jesse
> > Liberty.
> > But than you use it with operator + ( i.e. when you use two operators in
> one
> > assignment statement as I described ) the error is occured. What is the
> > matter?

> That'll teach me to post an answer while still drinking my first cup of
> coffee...

> delcare your operator+ like this:

> friend const Counter operator+(const Counter &lhs, const Counter &rhs);

> and its implementation:

>  const Counter operator+(const Counter &lhs, const Counter &rhs)
>  {
>     return Counter(lhs.itsVal + rhs.itsVal);
>  }

> BTW, in your example the line:

>     varTwo = varOne++ + varOne++;

> is not well defined. There is no "sequence point" between the increment
> operators on the varOne object. This makes the result undefined and
compiler
> dependent...

> HTH,
> Bruce

Re:Error: Operator 'operator' not implemented in type 'type'...


Vladimir Grigoriev,

Ok, you seem upset and that certainly wasn't my intention. If you have the
time I'll explain why I posted what I did. My intention was to assist and
advise you not to tell you off.

Quote
> Sorry but my question about C++ (I think about ANSI C++) not about compiler
> implementation.

Every release of every compiler aims to match the ANSI standard /as it was
when the compiler was released/. The compilers dealt with in this section are
all at least five years out of touch with the standard, some even more so.

Quote
> As for me there is no difference where to write letter.

There is if no one here knows about a particular Builder quirk or standards
change because they are all working to the 1997 (or whenever) ANSI standard.

Quote
> I'd like to get answer about my question not about user group.

But you'll increase your chances of getting an answer if you post to the
section set aside for your tool. This time you appear to have been lucky but
don't count on it.

By posting here you are running the risk of:

  * Getting an obsolete and innappropriate response.
  * Failing to get the answer you need because few people familiar with
Builder are visiting this section.

If for some reason you want to ask questions concerning the ANSI C++ standard
as it was back in 1997 then, sure, this is the place to ask. OTOH you are
using a compiler that is considerably more recent and that adheres to a more
modern version of the standard.

You also have the opportunity to have your questions read by far more people
if you post to .CPPBUILDER but, again, if you'd rather stick to a smaller
audience then fine.

I have nothing against this section as I still have to use BC4.51
occasionally but as a Builder user you can (and should IMO) aspire to
something better :)
--
Andrue Cope
[Bicester, UK]

Re:Error: Operator 'operator' not implemented in type 'type'...


Thank Andrue for your advice! I obligatory take it into account than I will
have new questions.
With best regards. Vladimir Grigoriev.

Andrue Cope <not.a.va...@email.address.sorry> ??? a
????:VA.00001cf4.06b13...@email.address.sorry...

Quote
> Vladimir Grigoriev,

> Ok, you seem upset and that certainly wasn't my intention. If you have the
> time I'll explain why I posted what I did. My intention was to assist and
> advise you not to tell you off.

> > Sorry but my question about C++ (I think about ANSI C++) not about
compiler
> > implementation.

> Every release of every compiler aims to match the ANSI standard /as it was
> when the compiler was released/. The compilers dealt with in this section
are
> all at least five years out of touch with the standard, some even more so.

> > As for me there is no difference where to write letter.

> There is if no one here knows about a particular Builder quirk or
standards
> change because they are all working to the 1997 (or whenever) ANSI
standard.

> > I'd like to get answer about my question not about user group.

> But you'll increase your chances of getting an answer if you post to the
> section set aside for your tool. This time you appear to have been lucky
but
> don't count on it.

> By posting here you are running the risk of:

>   * Getting an obsolete and innappropriate response.
>   * Failing to get the answer you need because few people familiar with
> Builder are visiting this section.

> If for some reason you want to ask questions concerning the ANSI C++
standard
> as it was back in 1997 then, sure, this is the place to ask. OTOH you are
> using a compiler that is considerably more recent and that adheres to a
more
> modern version of the standard.

> You also have the opportunity to have your questions read by far more
people
> if you post to .CPPBUILDER but, again, if you'd rather stick to a smaller
> audience then fine.

> I have nothing against this section as I still have to use BC4.51
> occasionally but as a Builder user you can (and should IMO) aspire to
> something better :)
> --
> Andrue Cope
> [Bicester, UK]

Re:Error: Operator 'operator' not implemented in type 'type'...


" Bruce Salzman" <br...@nospam.org> writes:

Quote
> BTW, in your example the line:

>     varTwo = varOne++ + varOne++;

> is not well defined. There is no "sequence point" between the increment
> operators on the varOne object. This makes the result undefined and compiler
> dependent...

Not in this case. If Counter were a built-in type, you'd be right. But since
it's a user-defined type, each operator is a function, and there's a
sequence point on function entry and one on function exit.

So while we don't know which summand is evaluated first, not only is the
behavior defined, but the outcome is also predictable.

Other Threads