RE: Abstract class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kolesar wrote:

> tmp->dispatch(session_cntx_impl(5));

The problem is that the temporary session_cntx_impl created here is implicitly const whereas dispatch expects a non-const reference. One way to fix this is to create a non-const session_cntx_impl, e.g.

    session_cntx_impl ctximp(5);
    tmp->dispatch(ctximp);

or, as you tried, make the dispatch function accept const references. The error you got then

> error: passing ‘const context_fnc’ as ‘this’ argument of ‘virtual
> void context_fnc::exec()’ discards qualifiers

means you need to keep adding const; you have a const context_fnc object but you're trying to call a non-const method, exec(), on it. If you make exec() a const method throughout your code i.e.

    virtual void exec() const = 0;

(and in the subclass and in the method declaration) then this should compile correctly.

Whether you want to add the consts or create the non-const session_cntx_impl depends on what your exec() methods do and whether they can always work on const objects.

Rup.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux