C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing a function pointer as an argument to an overloaded >

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
glen stark
Guest





PostPosted: Mon Sep 29, 2003 12:29 pm    Post subject: Passing a function pointer as an argument to an overloaded > Reply with quote



Hi all.

I'm working with an array of member function pointers (they are all get
function of the class Bead). The typedef is:

typedef _real (Bead::*_beadGfp)(void);

I have a class System which contains both an array of function pointers:

std::vector<_beadGfp> msmtFPs;

And an array of pointers to RTSM, a class I've implemented for measurements.

std::vector<RTSM*> msmtPts;

I've overloaded the input operator '>>' for a value of _real (which is
just a typedef for long double)

//! Add a value to the time series
INLINE RTSM& operator>>(_real& is, RTSM& rtsm){
rtsm.bin[rtsm.bindex] = is;
++rtsm.bindex;
return rtsm;
}

And I'm trying call the member function, and feed the value it returns
into it's corresponding RTSM object. The code is this:

void System::do_measurements(){
for (_index i = 0; i<msmtPts.size(); ++i){
_real sh_t = (bead.*msmtFPs[i])();
(a) sh_t >>*(msmtPts[i]);
(b) bead.*(msmtFPs[i])()>> *(msmtPts[i]);
}
}
(a) works., (b) gives me:

system.cpp: In member function `void System::do_measurements()':
system.cpp:161: no match for `_real (Bead::*&)() >> RTSM&' operator
results.hpp:24: candidates are: RM& operator>>(_real&, RM&)
results.hpp:81: RTSM& operator>>(_real&, RTSM&)

which I guess a few of you would predict. Although I may understant why
this happens, I don't know how to get around it, other than by declaring
a temporary variable like (a). Can someone educate me?

Thanks,

Glen Stark.
(www.glenstark.org)

Back to top
Victor Bazarov
Guest





PostPosted: Mon Sep 29, 2003 3:39 pm    Post subject: Re: Passing a function pointer as an argument to an overload Reply with quote



"glen stark" <mail (AT) glenstark (DOT) org.nospam> wrote...
Quote:
I'm working with an array of member function pointers (they are all get
function of the class Bead). The typedef is:

typedef _real (Bead::*_beadGfp)(void);

I have a class System which contains both an array of function pointers:

std::vector<_beadGfp> msmtFPs;

That's a vector specialised for _beadGfp, not an array.

Quote:
And an array of pointers to RTSM, a class I've implemented for
measurements.

std::vector<RTSM*> msmtPts;

This is not an array, as well. It's a vector. The two do differ.

Quote:
I've overloaded the input operator '>>' for a value of _real (which is
just a typedef for long double)

//! Add a value to the time series
INLINE RTSM& operator>>(_real& is, RTSM& rtsm){
rtsm.bin[rtsm.bindex] = is;
++rtsm.bindex;
return rtsm;
}

And I'm trying call the member function, and feed the value it returns
into it's corresponding RTSM object. The code is this:

void System::do_measurements(){
for (_index i = 0; i<msmtPts.size(); ++i){
_real sh_t = (bead.*msmtFPs[i])();

How is 'bead' declared? Are you sure the sizes are the same (so
there is no logical error)? You're treading a thin line of too
many assumptions here... It would be best to leave very little
to imagination. Not that it matters too much, though...

Quote:
(a) sh_t >>*(msmtPts[i]);
(b) bead.*(msmtFPs[i])()>> *(msmtPts[i]);
}
}
(a) works., (b) gives me:

system.cpp: In member function `void System::do_measurements()':
system.cpp:161: no match for `_real (Bead::*&)() >> RTSM&' operator
results.hpp:24: candidates are: RM& operator>>(_real&, RM&)
results.hpp:81: RTSM& operator>>(_real&, RTSM&)

which I guess a few of you would predict. Although I may understant why
this happens, I don't know how to get around it, other than by declaring
a temporary variable like (a). Can someone educate me?

Make your operator>> accept a const _real& or just _real:

RTSM& operator >> (_real, RTSM&);

A temporary cannot be bound to a non-const reference.

Victor



Back to top
Kevin Goodsell
Guest





PostPosted: Mon Sep 29, 2003 6:48 pm    Post subject: Re: Passing a function pointer as an argument to an overload Reply with quote



glen stark wrote:
Quote:
Hi all.

I'm working with an array of member function pointers (they are all get
function of the class Bead). The typedef is:

typedef _real (Bead::*_beadGfp)(void);

_real and _beadGfp are reserved identifiers in the global namespace. I
hope you are doing this inside your own namespace or a class.

In general, identifiers beginning with an underscore may be used by the
implementation, therefore you should probably not use them. Some
identifiers of this form are allowed in some contexts, but in order to
avoid problems it's probably best to avoid ever using an identifier that
begins with an underscore.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


Back to top
glen stark
Guest





PostPosted: Tue Sep 30, 2003 8:25 am    Post subject: Re: Passing a function pointer as an argument to an overload Reply with quote

Victor Bazarov wrote:

Quote:
"glen stark" <mail (AT) glenstark (DOT) org.nospam> wrote...

I'm working with an array of member function pointers (they are all get
function of the class Bead). The typedef is:

typedef _real (Bead::*_beadGfp)(void);

I have a class System which contains both an array of function pointers:

std::vector<_beadGfp> msmtFPs;


That's a vector specialised for _beadGfp, not an array.

Yeah, ooops, I knew that... I just ran 30k on Sunday, that's my excuse,
and I'm sticking to it.
Quote:
And an array of pointers to RTSM, a class I've implemented for

measurements.

std::vector<RTSM*> msmtPts;


This is not an array, as well. It's a vector. The two do differ.
See above


Quote:
I've overloaded the input operator '>>' for a value of _real (which is
just a typedef for long double)

//! Add a value to the time series
INLINE RTSM& operator>>(_real& is, RTSM& rtsm){
rtsm.bin[rtsm.bindex] = is;
++rtsm.bindex;
return rtsm;
}

And I'm trying call the member function, and feed the value it returns
into it's corresponding RTSM object. The code is this:

void System::do_measurements(){
for (_index i = 0; i<msmtPts.size(); ++i){
_real sh_t = (bead.*msmtFPs[i])();


How is 'bead' declared? Are you sure the sizes are the same (so
there is no logical error)? You're treading a thin line of too
many assumptions here... It would be best to leave very little
to imagination. Not that it matters too much, though...

bead is an instance of the Bead class (there's only one bead, so I was
boring about the naming). Is that what you're asking? I'm not sure
what you're getting at here.
Quote:

(a) sh_t >>*(msmtPts[i]);
(b) bead.*(msmtFPs[i])()>> *(msmtPts[i]);
}
}
(a) works., (b) gives me:

system.cpp: In member function `void System::do_measurements()':
system.cpp:161: no match for `_real (Bead::*&)() >> RTSM&' operator
results.hpp:24: candidates are: RM& operator>>(_real&, RM&)
results.hpp:81: RTSM& operator>>(_real&, RTSM&)

which I guess a few of you would predict. Although I may understant why
this happens, I don't know how to get around it, other than by declaring
a temporary variable like (a). Can someone educate me?


Make your operator>> accept a const _real& or just _real:

RTSM& operator >> (_real, RTSM&);

A temporary cannot be bound to a non-const reference.

Victor

Thanks, that's clear to me now.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.