Abstract class
Kolesar
asim.husanovic@gmail.com
Wed Dec 24 10:09:00 GMT 2008
Hi all
this code work on windows, and can compile with Visual studio 2003 c++, but
width g++, i get error:
In function ‘int main(int, char**)’:
:62: error: no matching function for call to
‘api_cntx::dispatch(session_cntx_impl)’
:42: note: candidates are: int api_cntx::dispatch(context_fnc&)
#include <iostream>
using namespace std;
class session_cntx
{
public:
session_cntx(){};
};
class context_fnc
{
public:
context_fnc() {};
virtual void exec() = 0;
};
class session_cntx_impl : public context_fnc
{
public:
session_cntx_impl(int ctx) : m_ctx(ctx) {}
virtual void exec();
private:
int m_ctx;
};
void session_cntx_impl::exec()
{
//
}
class api_cntx
{
public: api_cntx(){};
int dispatch(context_fnc& func) throw();
};
int api_cntx::dispatch(context_fnc& func) throw()
{
try
{
func.exec();
}
catch (...)
{
}
return 0;
}
int main(int argc, char* argv[])
{
session_cntx ctx;
api_cntx *tmp = new api_cntx();
tmp->dispatch(session_cntx_impl(5));
return 0;
}
If i put const into dispatch function, i get new error:
: In member function ‘int api_cntx::dispatch(const context_fnc&)’:
:46: error: passing ‘const context_fnc’ as ‘this’ argument of ‘virtual void
context_fnc::exec()’ discards qualifiers
Please help me.
BR
Kolesar
--
View this message in context: http://www.nabble.com/Abstract-class-tp21156603p21156603.html
Sent from the gcc - Help mailing list archive at Nabble.com.
More information about the Gcc-help
mailing list