S
subramanian100in
The following quesion is NOT a HOMEWORK problem.
Consider the following x.cpp:
#include <cstdlib>
#include <iostream>
using namespace std;
template<class T>
inline void fn(void (T::*memfnPtr)())
{
return;
}
class Test
{
public:
void member();
void member() const;
};
inline void Test::member(void)
{
cout << "Test::member() called" << endl;
return;
}
inline void Test::member(void) const
{
cout << "Test::member() const called" << endl;
return;
}
int main()
{
fn(&Test::member);
return EXIT_SUCCESS;
}
When I compile this program with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
I get the following compilation error:
x.cpp: In function `int main()':
x.cpp:35: error: no matching function for call to `fn(<unknown type>)'
Why do I get this compilation error ? Kindly explan. Please help to
fix this error. I do not get the compilation error, if I have the
function template 'fn()' as follows:
template<class T>
inline void fn(void (T::*memfnPtr)() const)
{
return;
}
Note that in the above modified version of 'fn()', I have added
'const' to the parameter. Why don't I get the compilation error
for this version but I do get for the earlier version ?
Thanks
V.Subramanian
Consider the following x.cpp:
#include <cstdlib>
#include <iostream>
using namespace std;
template<class T>
inline void fn(void (T::*memfnPtr)())
{
return;
}
class Test
{
public:
void member();
void member() const;
};
inline void Test::member(void)
{
cout << "Test::member() called" << endl;
return;
}
inline void Test::member(void) const
{
cout << "Test::member() const called" << endl;
return;
}
int main()
{
fn(&Test::member);
return EXIT_SUCCESS;
}
When I compile this program with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
I get the following compilation error:
x.cpp: In function `int main()':
x.cpp:35: error: no matching function for call to `fn(<unknown type>)'
Why do I get this compilation error ? Kindly explan. Please help to
fix this error. I do not get the compilation error, if I have the
function template 'fn()' as follows:
template<class T>
inline void fn(void (T::*memfnPtr)() const)
{
return;
}
Note that in the above modified version of 'fn()', I have added
'const' to the parameter. Why don't I get the compilation error
for this version but I do get for the earlier version ?
Thanks
V.Subramanian