A
Adrian
Example A fails to compile with
exampleA.cpp: In member function 'void A::a() const':
exampleA:10: error: no matching function for call to 'A::b(const
std::string&) const'
exampleA:17: note: candidates are: virtual void (* A::b(const
std::string&))()const <near match>
Example B compiles fine.
Now I assume that the const is not binding to what I think it should
in the example A
Adding the typedef fixes this
Can anyone tell me what is going on
Adrian
+++++++++++++ Example A +++++++++++++++
#include <iostream>
#include <string>
class A
{
public:
void a() const
{
const std::string arg("test");
void(*func_ptr)(void)=b(arg);
if(func_ptr)
{
}
};
virtual ~A() throw();
virtual void (*b(const std::string &str))(void) const=0;
};
int main(int argc, char *argv[])
{
return 0;
}
+++++++++++++ Example B +++++++++++++++
#include <iostream>
#include <string>
class A
{
public:
typedef void(*func_ptr)(void);
void a() const
{
const std::string arg("test");
func_ptr func_ptr=b(arg);
if(func_ptr)
{
}
};
virtual ~A() throw();
virtual func_ptr b(const std::string &str) const=0;
};
int main(int argc, char *argv[])
{
return 0;
}
exampleA.cpp: In member function 'void A::a() const':
exampleA:10: error: no matching function for call to 'A::b(const
std::string&) const'
exampleA:17: note: candidates are: virtual void (* A::b(const
std::string&))()const <near match>
Example B compiles fine.
Now I assume that the const is not binding to what I think it should
in the example A
Adding the typedef fixes this
Can anyone tell me what is going on
Adrian
+++++++++++++ Example A +++++++++++++++
#include <iostream>
#include <string>
class A
{
public:
void a() const
{
const std::string arg("test");
void(*func_ptr)(void)=b(arg);
if(func_ptr)
{
}
};
virtual ~A() throw();
virtual void (*b(const std::string &str))(void) const=0;
};
int main(int argc, char *argv[])
{
return 0;
}
+++++++++++++ Example B +++++++++++++++
#include <iostream>
#include <string>
class A
{
public:
typedef void(*func_ptr)(void);
void a() const
{
const std::string arg("test");
func_ptr func_ptr=b(arg);
if(func_ptr)
{
}
};
virtual ~A() throw();
virtual func_ptr b(const std::string &str) const=0;
};
int main(int argc, char *argv[])
{
return 0;
}