Hi all,
I've run into something confusing on MS VC6. Yeah I know it's old but
that's what the client wants, so...
I'm trying to pass a pointer to a member function as a template
argument, and the compiler gives me an invalid template argument on the
member function address if the member function returns a type. A
member function with a void return type is fine. The example below
demonstrates the problem:
class SomeClass
{
int FuncWithReturn(){return 0;}
void VoidFunc(int arg){};
};
template TemplateRetFunc<class T, class RetType, RetType (T::*F)() >
{
};
template TemplateVoidFunc<class T, class Arg, void (T::*F)(Arg) >
{
};
int main()
{
TemplateRetFunc<SomeClass, int, &SomeClass::FuncWithReturn> test1;
//error
TemplateVoidFunc<SomeClass, int, &SomeClass::VoidFunc> test2; //OK
return 0;
}
Anyone know why having the return type gives an error? I'm fine if I
have to use a void return, I just want to know why.
Damien
Damien 4 7301
Damien wrote: I've run into something confusing on MS VC6. Yeah I know it's old but that's what the client wants, so...
I'm trying to pass a pointer to a member function as a template argument, and the compiler gives me an invalid template argument on the member function address if the member function returns a type. A member function with a void return type is fine. The example below demonstrates the problem:
class SomeClass { int FuncWithReturn(){return 0;} void VoidFunc(int arg){}; };
template TemplateRetFunc<class T, class RetType, RetType (T::*F)() > { };
template TemplateVoidFunc<class T, class Arg, void (T::*F)(Arg) > { };
int main() { TemplateRetFunc<SomeClass, int, &SomeClass::FuncWithReturn> test1; //error TemplateVoidFunc<SomeClass, int, &SomeClass::VoidFunc> test2; //OK return 0; }
Anyone know why having the return type gives an error? I'm fine if I have to use a void return, I just want to know why.
VC6 is really bad when it comes to templates. Try to convince your client
to upgrade or to change the compiler.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Damien wrote: Hi all,
I've run into something confusing on MS VC6. Yeah I know it's old but that's what the client wants, so...
I'm trying to pass a pointer to a member function as a template argument, and the compiler gives me an invalid template argument on the member function address if the member function returns a type. A member function with a void return type is fine. The example below demonstrates the problem:
class SomeClass {
public:
int FuncWithReturn(){return 0;} void VoidFunc(int arg){}; };
template TemplateRetFunc<class T, class RetType, RetType (T::*F)() >
Syntax error!
{ };
template TemplateVoidFunc<class T, class Arg, void (T::*F)(Arg) > { };
int main() { TemplateRetFunc<SomeClass, int, &SomeClass::FuncWithReturn> test1; //error TemplateVoidFunc<SomeClass, int, &SomeClass::VoidFunc> test2; //OK return 0; }
Anyone know why having the return type gives an error? I'm fine if I have to use a void return, I just want to know why.
Compiler bug/non-compliance issue. VC6 has lots of them.
Tom
Oh, this is embarrassing. In my haste to throw together a non-client
example I wrote utter rubbish instead of valid C++. Note to self:
Always compile examples, even little ones. Should have been:
class SomeClass
{
public:
int FuncWithReturn(){return 0;}
void VoidFunc(int arg){};
};
template <class T, class RetType, RetType (T::*F)() > class
TemplateRetFunc
{
};
template <class T, class Arg, void (T::*F)(Arg)> class TemplateVoidFunc
{
};
int main()
{
TemplateRetFunc<SomeClass, int, &SomeClass::FuncWithReturn> test1;
//error
TemplateVoidFunc<SomeClass, int, &SomeClass::VoidFunc> test2; //OK
return 0;
}
Which is fine under gcc, but barfs on VC6. Might have to encourage an
upgrade.
Sorry for wasting your time on stupid code.
Damien
Damien wrote: Hi all,
I've run into something confusing on MS VC6. Yeah I know it's old but that's what the client wants, so...
I'm trying to pass a pointer to a member function as a template argument, and the compiler gives me an invalid template argument on the member function address if the member function returns a type. A member function with a void return type is fine. The example below demonstrates the problem:
class SomeClass { int FuncWithReturn(){return 0;} void VoidFunc(int arg){}; };
template TemplateRetFunc<class T, class RetType, RetType (T::*F)() > { };
template TemplateVoidFunc<class T, class Arg, void (T::*F)(Arg) > { };
int main() { TemplateRetFunc<SomeClass, int, &SomeClass::FuncWithReturn> test1; //error TemplateVoidFunc<SomeClass, int, &SomeClass::VoidFunc> test2; //OK return 0; }
Anyone know why having the return type gives an error? I'm fine if I have to use a void return, I just want to know why.
Damien
Damien
vc6.0sp4 fails to compile the following perfectly valid C++ code as
well. Try a better compiler.
#include <vector>
#include <iostream>
template<typename T>
class MyArray {
public:
MyArray();
~MyArray();
void append(const T& item);
void display();
private:
std::vector<T> *v;
};
template<typename T>
MyArray<T>::MyArray() {
v = new std::vector<T>();
}
template<typename T>
MyArray<T>::~MyArray() {
delete v;
}
template<typename T>
void MyArray<T>::append(const T& item) {
v->push_back(item);
}
template<typename T>
void MyArray<T>::display() {
typename std::vector<T>::iterator ivi;
for(ivi = v->begin(); ivi != v->end(); ++ivi)
std::cout << *ivi << std::endl;
}
int main(int argc, char** argv) {
MyArray<std::string> ma1;
ma1.append("Test1");
ma1.append("Test2");
ma1.display();
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Stippler |
last post by:
Can someone explain the following construct to me:
What is not clear to me is what the argument to foo is.
A pointer to a member?
template <class U>
static char foo(void (U::*)(void));
...
|
by: jimjim |
last post by:
Hello,
My question concerns as to how a pointer is passed by reference as a
function argument. The following is from code taken from the MICO
implementation of the CORBA specification.
in...
|
by: Gert Van den Eynde |
last post by:
Hi all,
A beginners question....
I've got a template class
template <class T> classA {...}
In an other class, I want to pass a pointer to an instance of classA as a
function argument....
|
by: Albert |
last post by:
Hi,
I need to pass a pointer-to-member-function as a parameter to a function
which takes pointer-to-function as an argument. Is there any way to do it
besides overloading the function?
Here...
|
by: firegun9 |
last post by:
Hello everyone,
here is my program:
///////////////////////////////
#include <iostream>
using namespace std;
void multi(double* arrayPtr, int len){
for(int i=0; i<len; i++)...
|
by: ivan.leben |
last post by:
I am writing this in a new thread to alert that I found a solution to
the problem mentioned here:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8
and to avoid...
|
by: StephQ |
last post by:
This is from a thread that I posted on another forum some days ago.
I didn't get any response, so I'm proposing it in this ng in hope of
better luck :)
The standard explanation is that pointer...
|
by: autumn |
last post by:
Hi everybody,
I'm having problem passing pointer to member object as template argument, seems VC 2005 does not allow 'pointer to base member' to 'pointer to derived member' conversion in template...
|
by: ghulands |
last post by:
I am having trouble implementing some function pointer stuff in c++
An object can register itself for many events
void addEventListener(CFObject *target, CFEventHandler callback,
uint8_t...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |