Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++
archives and Stroustrup's FAQs (particularly the following:
<url:http://www.research.at t.com/~bs/bs_faq2.html#ov erload-dot/>)
I am left to wondering why Stroustrup doesn't mention the
*_cast<> operators or operator .* in that particular FAQ.
Archived discussions have convinced me that .* _cannot_ be overloaded.
I have gathered a notion (perhaps incorrectly) that the *_cast<>
operators cannot be overloaded as well. Hence this post.
Awaiting enlightenment.
--
Suman 5 2408
Suman wrote: Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++ archives and Stroustrup's FAQs (particularly the following: <url:http://www.research.at t.com/~bs/bs_faq2.html#ov erload-dot/>) I am left to wondering why Stroustrup doesn't mention the *_cast<> operators or operator .* in that particular FAQ. Archived discussions have convinced me that .* _cannot_ be overloaded. I have gathered a notion (perhaps incorrectly) that the *_cast<> operators cannot be overloaded as well. Hence this post.
Awaiting enlightenment.
-- Suman
I cant sure, but *_cast series seems KEYWORDS not OPERATOR?
Suman wrote: Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++ archives and Stroustrup's FAQs (particularly the following: <url:http://www.research.at t.com/~bs/bs_faq2.html#ov erload-dot/>) I am left to wondering why Stroustrup doesn't mention the *_cast<> operators or operator .* in that particular FAQ. Archived discussions have convinced me that .* _cannot_ be overloaded. I have gathered a notion (perhaps incorrectly) that the *_cast<> operators cannot be overloaded as well. Hence this post.
Awaiting enlightenment.
-- Suman
Do you mean such like static_cast<typ edef>?
I cant sure, but it seems is not a operator...
and the same, (typedef), () is not operator too...
Rayer wrote: Suman wrote: Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++ archives and Stroustrup's FAQs (particularly the following: <url:http://www.research.at t.com/~bs/bs_faq2.html#ov erload-dot/>) I am left to wondering why Stroustrup doesn't mention the *_cast<> operators or operator .* in that particular FAQ. Archived discussions have convinced me that .* _cannot_ be overloaded. I have gathered a notion (perhaps incorrectly) that the *_cast<> operators cannot be overloaded as well. Hence this post.
Awaiting enlightenment.
-- Suman Do you mean such like static_cast<typ edef>? I cant sure, but it seems is not a operator...
<url: http://cs.stmarys.ca/~porter/csc/ref/cpp_operators.h tml/>
should help you.
Suman wrote: Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++ archives and Stroustrup's FAQs (particularly the following: <url:http://www.research.at t.com/~bs/bs_faq2.html#ov erload-dot/>) I am left to wondering why Stroustrup doesn't mention the *_cast<> operators or operator .* in that particular FAQ. Archived discussions have convinced me that .* _cannot_ be overloaded. I have gathered a notion (perhaps incorrectly) that the *_cast<> operators cannot be overloaded as well. Hence this post.
Awaiting enlightenment.
You can define a conversion operator (this probably has some real name,
but I don't know it off the top of my head). Example:
class A
{
} ;
class B
{
public:
operator A()
{
// Do what ever is needed to "cast" this to type A.
A a ;
return a ;
}
} ;
This would enable something like:
B b ;
A a ;
a = static_cast<A>( b) ; // cast is unnecessary here.
--
Alan Johnson
"Suman" <sk*****@gmail. com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. . Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++ archives and Stroustrup's FAQs (particularly the following: <url:http://www.research.at t.com/~bs/bs_faq2.html#ov erload-dot/>) I am left to wondering why Stroustrup doesn't mention the *_cast<> operators or operator .* in that particular FAQ. Archived discussions have convinced me that .* _cannot_ be overloaded. I have gathered a notion (perhaps incorrectly) that the *_cast<> operators cannot be overloaded as well. Hence this post.
Awaiting enlightenment.
Well, aren't we all? ;-)
You cannot directly overload "operators" like static_cast<> but what you can
do is to overload the conversion operators that are invoked upon the use of
a cast. For example:
class MyString {
public:
.....
operator char*(); // Here you could implement the desired behavior when
a cast to char* is required.
}
But you should be very careful with this, as sometimes casting might be
performed implicitely and this can open Pandora's box!!
The operator ".*" cannot be overloaded at all.
HTH
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Piotre Ugrumov |
last post by:
I have tried to implement the overload of these 2 operators.
ostream & operator<<(ostream &out, Person &p){
out<<p.getName()<<" "<<p.getSurname()<<", "<<p.getDateOfBirth()<<endl;
return out;
}
This overload work but I have a curiosty
If I try to approch to the name or to the surname or to the dateofbirth in
this way i receive error:
ostream & operator<<(ostream &out, Person &p){
out<<p.name<<" "<<p.surname<<", "<<p.dateofbirth<<endl;
|
by: Dave |
last post by:
Hello all,
After perusing the Standard, I believe it is true to say that once you
insert an element into a std::list<>, its location in memory never changes.
This makes a std::list<> ideal for storing vertices of an arbitrary n-ary
tree where a vertex contain pointers to its parent / children. These parent
/ child vertices need to stay put if we've got pointers to them somewhere!
Am I correct in my assertion?
|
by: ESPNSTI |
last post by:
Hi,
I'm trying to use a generics dictionary with a key class that implements and
needs IComparable<>.
However when I attempt to use the dictionary, it doesn't appear to use the
IComparable<> to find the key.
In the example below, accessing the dictionary by using the exact key object
that was used to add to the dictionary works.
(see code comment 1).
However, if I attempt to access the dictionary by using a key object that
|
by: SoilMan |
last post by:
Consider the following:
class xyz
{
public:
template <typename T>
void foo(T x)
{
cout << "foo<T> " << x << endl;
}
|
by: brzozo2 |
last post by:
Hello, this program might look abit long, but it's pretty simple and
easy to follow. What it does is read from a file, outputs the contents
to screen, and then writes them to a different file. It uses map<and
heavy overloading.
The problem is, the output file differs from input, and for the love of
me I can't figure out why ;p
#include <iostream>
#include <fstream>
#include <sstream>
| |
by: Squeamizh |
last post by:
class my_class {
public:
my_class() : value(0) { }
int& get_value() { return value; }
const int& get_value() const {
my_class& c = const_cast<my_class&>(*this);
return c.get_value();
}
|
by: Andrew Robinson |
last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v>
depending on input parameters and options to the method.
1. Is there any way to convert from a dictionary to a list without
itterating through the entire collection and building up a list?
2. is there a common base class, collection or interface that can contain
either/both of these collection types and then how do you convert or cast
from the base to either a...
|
by: Peterwkc |
last post by:
Hello all expert C++ programmer, i fairly new to C++ programming.
I have a class cellphone which contain dynamic pointer.
I have create (example)ten cellphone.
I want to ask user for the input and store in the list and finally sort the list according to the brand of cellphone.
I learn C++ by myself. Therefore, i hope someone can guide me in this matter. I not asking for solution but guideline.
|
by: baltasarq |
last post by:
Hi, there !
When I use dynamic_cast for a single object, I do something like:
void foo(Base *base)
{
if ( dynamic_cast<Derived *>( base ) != NULL ) {
((Derived *) base)->do_something()
}
}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |