473,473 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

overloading operator ->*


Does anyone know of an example of overloading operator ->*

Cheers

JB
Nov 25 '05 #1
6 1907
n2xssvv g02gfr12930 wrote:

Does anyone know of an example of overloading operator ->*


Austria C++ has "smart pointers" that do this.

The operator needs to return a pointer.

struct T
{
int x;
};

struct X
{

T * m_ptr;

T * operator->()
{
return m_ptr;
}
};
Nov 25 '05 #2
Gianni Mariani wrote:
n2xssvv g02gfr12930 wrote:

Does anyone know of an example of overloading operator ->*

Austria C++ has "smart pointers" that do this.

The operator needs to return a pointer.

struct T
{
int x;
};

struct X
{

T * m_ptr;

T * operator->()
{
return m_ptr;
}
};


That's not an example of overloading 'operator ->*' but 'operator ->'.

JB
Nov 26 '05 #3
ben
n2xssvv g02gfr12930 wrote:

Does anyone know of an example of overloading operator ->*

Cheers

JB

How do you overload two operators at the same time???
Ben
Nov 26 '05 #4
ben wrote:
n2xssvv g02gfr12930 wrote:

Does anyone know of an example of overloading operator ->*

Cheers

JB


How do you overload two operators at the same time???
Ben


->* is only one operator, just like .*

The are used with 'pointers to members'. Look them up in your favourite
C++ book.

john
Nov 26 '05 #5
What does ->* do? and what does .* do?

Nov 26 '05 #6
n2xssvv g02gfr12930 wrote:

That's not an example of overloading 'operator ->*' but 'operator ->'.


Yep, you're right. My mistake.
struct S
{
int z;

int & operator ->* ( int S::* const & x )
{
return this->*x;
}

};

struct Y
{
int z;

template <typename T>
T & operator ->* ( T Y::* const & x )
{
return this->*x;
}

};

int main()
{
S s;
int S::* pmz = &S::z;

s->*( pmz ) = 3;

Y y;
int Y::* pmy = &Y::z;

y->*( pmy ) = 3;
}
Nov 26 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. ...
5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
2
by: pmatos | last post by:
Hi all, I'm overloading operator<< for a lot of classes. The question is about style. I define in each class header the prototype of the overloading as a friend. Now, where should I define the...
5
by: luca regini | last post by:
I have this code class M { ..... T operator()( size_t x, size_t y ) const { ... Operator overloading A ....} T& operator()( size_t x, size_t y )
5
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
9
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
1
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...
0
tracyyun
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...
1
isladogs
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.