Newsgroup: comp.lang.c++
Subject: const_cast member function pointer
From: nick.keighley.zczc@...
Date: Fri, 25 Oct 2013 02:49:25 -0700 (PDT)
Yes I read the FAQ! I'm not using a typedef as they don't seem to work with templates in C++98.
template<typename WB>
void EditProgramWizard::PopulateButton (MParameterButton* paramButton, WB* band,
int (WB::*read)(),
void (WB::*write)(int))
{
int (WB::*const_read)() = const_cast<int (WB::*)() const> (read);
PopulateButton (paramButton, band, const_read, write);
}
the cast fails with:
myprog.cpp: In member function ?void EditProgramWizard::PopulateButton(MParameterButton *, WB*, int (WB::*)(), void (WB::*)(int)) [with WB = WeightBand]?:
myprog.cpp:464:125: instantiated from here
myprog.cpp:1521:68: error: invalid use of const_cast with type ?int (WeightBand::*)()const?, which is not a pointer, reference, nor a pointer-to-data-member type
I was under the impression ?int (WeightBand::*)()const' *was* a pointer.
Oh. Are pointers to member functions not const castable?
Subject: const_cast member function pointer
From: nick.keighley.zczc@...
Date: Fri, 25 Oct 2013 02:49:25 -0700 (PDT)
Yes I read the FAQ! I'm not using a typedef as they don't seem to work with templates in C++98.
template<typename WB>
void EditProgramWizard::PopulateButton (MParameterButton* paramButton, WB* band,
int (WB::*read)(),
void (WB::*write)(int))
{
int (WB::*const_read)() = const_cast<int (WB::*)() const> (read);
PopulateButton (paramButton, band, const_read, write);
}
the cast fails with:
myprog.cpp: In member function ?void EditProgramWizard::PopulateButton(MParameterButton *, WB*, int (WB::*)(), void (WB::*)(int)) [with WB = WeightBand]?:
myprog.cpp:464:125: instantiated from here
myprog.cpp:1521:68: error: invalid use of const_cast with type ?int (WeightBand::*)()const?, which is not a pointer, reference, nor a pointer-to-data-member type
I was under the impression ?int (WeightBand::*)()const' *was* a pointer.
Oh. Are pointers to member functions not const castable?
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?115142-const_cast-member-function-pointer&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment