About Borland C++BuilderX's 2 questions

D

DarkSpy

Question 1:
class A
{
public:
operator int () { return 10; }
operator int () const { return operator int(); }

operator std::string() { return "abcd"; }
operator std::string() const { return operator std::string(); }
};
that was error with "operator int() const", message is:
"1.cpp": E2015 Ambiguity between 'A::eek:perator int()' and 'A::eek:perator
int() const' in function A::eek:perator int() const at line 14
ok, i change it to:
operator int () const { return this->operator int(); }
that was ok.

why "operator std::string() const" was pass ? is it the ISO C++'s rule
or compiler's bug ?

Question 2:
class A
{
public:
void * operator new (size_t size) { ... }
void operator delete (void *p) { ... }

void * operator new (size_t size, void *p) { ... }
//placement new
void operator delete(void *p1, void *p2) { ... }
//placement delete
};

that whas error with two "operator delete functions"

with "void operator delete(void *p1, void *p2) { ... } "
1.cpp": E2238 Multiple declaration for 'A' at line 21

with "void operator delete (void *p) { ... }"
1.cpp": E2344 Earlier declaration of 'A' at line 10

when i deleted *ANY* one of the "operator delete" function, that was
ok.

is the void operator delete (void *p1, void *p2) do nothing with
placement operator new ?, because the C++BuilderX 's help document
wrote:

The second function (means: void operator delete(void *, void *); ) is
called by a placement delete expression corresponding to a new
expression of the form new(std::size_t). It does nothing.


thanks all anyway.
 
D

DarkSpy

Rolf Magnus said:
It should however result in an endless loop, since the this object is
const within operator int() const, and so the const operator must be
called again.


I think both should pass, but both should result in an endless loop for
the const operator.


Is the above the exact code, exept from the '...'? Btw, it is usually
best to provide a minimal, but full program that is compilable except
from the error you observed. Do not just post code that never saw a
compiler.

thank you Rolf Magnus.

the first question's point is:
i know the const object will call "operator int() const" loop and
loop, but my question is: why the *keyword* type were can not pass
except add "this->" operate code ? is this an ISO C++'s rule or CBX's
bug ?

the second question's point is:
the source code is exact code, the "..." is my omission code, not
important, my question is: why compiler tell me: the "void operate
delete" is multiple declaration ? the function:
void operate delete(void *);
and
void operate delete(void *, void *);
is not same functions, so......

is this an ISO C++'s rule or CBX's bug ?

thanx anyway.
 
R

Rolf Magnus

DarkSpy said:
Question 1:
class A
{
public:
operator int () { return 10; }
operator int () const { return operator int(); }

operator std::string() { return "abcd"; }
operator std::string() const { return operator std::string(); }
};
that was error with "operator int() const", message is:
"1.cpp": E2015 Ambiguity between 'A::eek:perator int()' and 'A::eek:perator
int() const' in function A::eek:perator int() const at line 14
ok, i change it to:
operator int () const { return this->operator int(); }
that was ok.

It should however result in an endless loop, since the this object is
const within operator int() const, and so the const operator must be
called again.
why "operator std::string() const" was pass ? is it the ISO C++'s rule
or compiler's bug ?

I think both should pass, but both should result in an endless loop for
the const operator.
Question 2:
class A
{
public:
void * operator new (size_t size) { ... }
void operator delete (void *p) { ... }

void * operator new (size_t size, void *p) { ... }
//placement new
void operator delete(void *p1, void *p2) { ... }
//placement delete
};

that whas error with two "operator delete functions"

with "void operator delete(void *p1, void *p2) { ... } "
1.cpp": E2238 Multiple declaration for 'A' at line 21

with "void operator delete (void *p) { ... }"
1.cpp": E2344 Earlier declaration of 'A' at line 10

Is the above the exact code, exept from the '...'? Btw, it is usually
best to provide a minimal, but full program that is compilable except
from the error you observed. Do not just post code that never saw a
compiler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,372
Latest member
LucretiaFo

Latest Threads

Top