473,770 Members | 5,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a object's overloaded operator with a pointer to that object.

example:
FunClass myfun;
FunClass *lotsofunptr=&m yfun;

myfun[string]; //calls the overloaded [] operator;
lotsofunptr->[string];//error

help is much apreciated
Jul 22 '05 #1
3 1616
matt p wrote:
example:
FunClass myfun;
FunClass *lotsofunptr=&m yfun;

myfun[string]; //calls the overloaded [] operator;
How does your signature of the overloaded function look like ?
And what is 'string' . C++ std. specifies it to be a type in std
namespace.


lotsofunptr->[string];//error


Post compilable code here to seek help.

--
Karthik. http://akktech.blogspot.com .
'Remove _nospamplz from my email to mail me.'
Jul 22 '05 #2
Karthik Kumar wrote:
matt p wrote:
example:
FunClass myfun; FunClass *lotsofunptr=&m yfun;

myfun[string]; //calls the overloaded [] operator;
Assuming string to be a variable, (a bad choice for naming it
though) and of the same type as the overloaded function would expect ,
here it goes.

myfun[string] ;

is essentially

myfun.operator[](string)


How does your signature of the overloaded function look like ?
And what is 'string' . C++ std. specifies it to be a type in std
namespace.


lotsofunptr->[string];//error


So if you want to get the same thing as that of a pointer , use

(*lotsofunptr)[string];

You essentially dereference the pointer and apply the same syntax.
If you are not happy then use

lotofunptr->operator[](string)

That should work fine too.



Post compilable code here to seek help.

--
Karthik. http://akktech.blogspot.com .
'Remove _nospamplz from my email to mail me.'
Jul 22 '05 #3
matt p wrote:
example:
FunClass myfun;
FunClass *lotsofunptr=&m yfun;

myfun[string]; //calls the overloaded [] operator;
lotsofunptr->[string];//error


(* lotsofunptr) [string];

lotsofunptr->operator [] (string);

--
Salu2
Jul 22 '05 #4

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

Similar topics

8
17879
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. Why can't the = (assignment) operator be overloaded as a friend function ? I work in VS 6.0 ( Win2000 ) as when i referred the MSDN documen'n it said the following :
11
23059
by: Squid Seven | last post by:
I create a pointer to an item: CardSession *cardSession; Then, later, I use new to create an instance of the item and assign it to that pointer: cardSession = new CardSession(); In another function, I want to test if an object is assigned to that
4
4972
by: Michael | last post by:
Hello, I want to use an object (LowCut) within another object (SampleRateConverter) like it is written as follows: class SampleRateConverter { public: SampleRateConverter( int iSourceSampleRate, int iTargetSampleRate ) {
3
1446
by: Jesper | last post by:
Hi, I've made a class with the following operator overloads listed below. However, If I test a 'pointer' for an instace, I get an exception that the object is not set to an insstance of an object. ID id = new ID(1,2) ..... e.g. if ( id != null ) <- this line calls the static overload, I guees, instead of testing whether the id is set to an object or not. How do I test
5
1645
by: shaun roe | last post by:
I am about to replace a plain function which returns a string with an object; I am trying to preserve the interface to clients of the function, while imbuing the function with some internal state. lets say the function is string foo(int myInt); I thought to make an object with constructor f(int myInt) and hide the default constructor, copy, assignment (anything else?), but provide some
11
11056
by: Marco Wedekind | last post by:
Hello all, I have a strange compiler behaviour with this code: ---- Begin of code snippet ---- class Base { public: static unsigned int ClassId();
13
5042
by: Tristan Wibberley | last post by:
Hi I've got implementing overloaded operator new and delete pretty much down. Just got to meet the alignment requirements of the class on which the operator is overloaded. But how does one implement operator new/delete I can't see a way to indicate, on delete, how many objects must be destroyed (or how big the space is) - alternatively I can't figure out what are the alignment requirements so that the implementation, after calling my...
3
1212
by: Howard Swope | last post by:
Greetings: C++ CLR .Net 2 I have a ref class that I have created that wraps an unmanaged pointer. It acts like a smart pointer for reference counted objects for a particular library I am working in. I have overloaded the ->, *, assignment, and equality operators. I have created a ! finalizer and call it from my destructor. However, when I do so, the operator overload returns the type of the wrapped pointer.
4
1823
by: Encrypted | last post by:
i hav coded a matrix class and its member functions (many of them are overloaded ones)...now in a function..for eg. function of matrix addition.. after the addition i want to return the local object "result" through a pointer (and not call by value)..however i aint getting d values of the result in main()...instead i am getting garbage values when i print it... here is my code : #include <iostream.h> #include <stdio.h> #include...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
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 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...
0
9869
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 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...
1
7415
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 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...
0
6676
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();...
0
5312
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3970
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
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.