Topic: What about virtual operator in C++?
Author: rubenst%occs.nlm.nih.gov (Mike Rubenstein Phoenix Contract)
Date: Fri, 10 Feb 95 19:52:45 GMT Raw View
lmr (ren@math.ohio-state.edu) wrote:
> I am wondering if it is allowed to define virtual operator in C++.
> I can't find any reference in standard C++ book. Specifically, I want
> to define a conversion operator as:
> class A{
> virtual operator char* ()=0;
> };
> class B:A{
> char* b;
> operator char* (){return b;}
> };
> class C:A{
> char* c;
> operator char* (){return c;}
> };
> Of cause, this is a simplified version. Can I do this in C++? VC++2.0
> compiler compiles fine and runs fine with this. It invocates the right
> operators. I want to know what the standard says about virtual operator.
This is standard. Virtual conversion operators are mentioned explicitly in
the ARM (12.3.2). Most other operators and member functions can also be
virtual; the exceptions are constructorsand static member functions (including
overloaded operator new and operator delete).
--
Mike Rubenstein
Author: acw@ioc.co.uk (Andy Wilkins)
Date: Mon, 6 Feb 1995 10:13:31 GMT Raw View
In <3h1v09$3jj@math.mps.ohio-state.edu>, ren@math.ohio-state.edu (lmr) writes:
> I am wondering if it is allowed to define virtual operator in C++.
[ctrl-k]
Well why don't you bloody try it. Two minutes with a compiler, or a book,
would tell you.
______________________________________________________________________
Andy Wilkins acw@ioc.co.uk
______________________________________________________________________
Author: andys@thone.demon.co.uk (Andy Sawyer)
Date: Mon, 6 Feb 1995 15:24:33 +0000 Raw View
In article <D3KpqJ.qzM@ioc.co.uk> acw@ioc.co.uk "Andy Wilkins" writes:
> In <3h1v09$3jj@math.mps.ohio-state.edu>, ren@math.ohio-state.edu (lmr) writes:
> > I am wondering if it is allowed to define virtual operator in C++.
> [ctrl-k]
> Well why don't you bloody try it. Two minutes with a compiler, or a book,
> would tell you.
Which particular book defines the current ISO standard then? Oh, there isn't
one (just) yet.(standard OR book)..and as for 'try it with a compiler' -
which particular compiler would you suggest? I have a current release
compiler from an EXTREMELY large software company (you know who I mean :-),
which does not allow the use of templates, exceptions, relaxed overrides
and quite a lot of other stuff. Add to that there are, to my knowledge,
no compilers which can succesfully compile and instantiate the STL.
Given the above, your reply was about as helpful as a chocolate tea pot in
a forest fire.
(And in response to the original question, the answer is yes, you can have
virtual operators, since operators are functions which happen to have a
convenient calling syntax)
Regards,
Andy
--
* Andy Sawyer ** e-mail:andys@thone.demon.co.uk ** Compu$erve:100432,1713 **
The opinions expressed above are my own, but you are granted the right to
use and freely distribute them. I accept no responsibility for any injury,
harm or damage arising from their use. -- The Management.
Author: krotoff@top.rector.msu.su (Alexsander Krotoff)
Date: 7 Feb 1995 12:36:28 GMT Raw View
In article <3h1v09$3jj@math.mps.ohio-state.edu> (5 Feb 1995 02:33:29 -0500) lmr wrote:
: I am wondering if it is allowed to define virtual operator in C++.
: I can't find any reference in standard C++ book. Specifically, I want
: to define a conversion operator as:
: class A{
: virtual operator char* ()=0;
: };
: class B:A{
: char* b;
: operator char* (){return b;}
: };
: class C:A{
: char* c;
: operator char* (){return c;}
: };
: Of cause, this is a simplified version. Can I do this in C++? VC++2.0
: compiler compiles fine and runs fine with this. It invocates the right
: operators. I want to know what the standard says about virtual operator.
Your question contains an answer. VC++ is right, you may use virtual
operators. It does not mentioned in ARM and other books becouse there
is no any special rules for such operators.
: Many thanks!!
: --
: Liming Ren |
: Dept. of Mathematics | 231 West 18th Avenue
: The Ohio State University | Columbus, Ohio43210
--
Alexander Krotoff <krotoff@such.srcc.msu.su>
Research Computer Center [Moscow]939-2638
Moscow State University MGU, SRCC k316. GZ B-733r.
Author: ren@math.ohio-state.edu (lmr)
Date: 5 Feb 1995 02:33:29 -0500 Raw View
I am wondering if it is allowed to define virtual operator in C++.
I can't find any reference in standard C++ book. Specifically, I want
to define a conversion operator as:
class A{
virtual operator char* ()=0;
};
class B:A{
char* b;
operator char* (){return b;}
};
class C:A{
char* c;
operator char* (){return c;}
};
Of cause, this is a simplified version. Can I do this in C++? VC++2.0
compiler compiles fine and runs fine with this. It invocates the right
operators. I want to know what the standard says about virtual operator.
Many thanks!!
--
Liming Ren |
Dept. of Mathematics | 231 West 18th Avenue
The Ohio State University | Columbus, Ohio43210
Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Sun, 5 Feb 1995 14:28:02 GMT Raw View
In <3h1v09$3jj@math.mps.ohio-state.edu> ren@math.ohio-state.edu (lmr) writes:
>I am wondering if it is allowed to define virtual operator in C++.
Yes.
--
- Paul J. Lucas #ifndef COMMON_KNOWLEDGE
AT&T Bell Laboratories #include <stddisclaimer.h>
Naperville, IL #endif