G++ + C++ problem with const

Programming, for all ages and all languages.
Post Reply
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

G++ + C++ problem with const

Post by Candy »

Code: Select all

../include/aos/filter: In constructor `basic_filter<I, O>::basic_filter() [with I = byte, O = wchar_t]':
deutf16.cc:4:   instantiated from here
../include/aos/filter:64: error: no matching function for call to `input_obj<byte, basic_filter<byte, wchar_t> >::input_obj(void (basic_filter<byte, wchar_t>::*)(const byte&), basic_filter<byte, wchar_t>* const)'
../include/aos/input:21: note: candidates are: input_obj<byte, basic_filter<byte, wchar_t> >::input_obj(const input_obj<byte, basic_filter<byte, wchar_t> >&)
../include/aos/input:23: note:                 input_obj<I, C>::input_obj(void (C::*)(input_obj<I, C>*, const I&), C*) [with I = byte, C = basic_filter<byte, wchar_t>]
candy@blackbox:~/atlantisos/libaos$ gcc -v
Reading specs from /usr/lib/gcc/i486-slackware-linux/3.4.6/specs
Configured with: ../gcc-3.4.6/configure --prefix=/usr --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 3.4.6
I'm doing something wrong. Apparently it's passing the second argument as a const pointer to a variable argument (which could be correct, but why pass it as const? just make a copy on the stack) but it can't find a constructor that has that const pointer argument. The code it's calling:

Code: Select all

template <typename I, class C>
class input_obj : public input_<I> {
    public:
        input_obj(void (C::*cb)(input_obj *, const I &), C * const obj) : callback(cb), c(obj) {}
Being called from the parent of the instantiating class (instantiating class is deutf16, parent is basic_filter<I, O>):
basic_filter::basic_filter() :
_input(new input_obj<I, basic_filter<I, O> >(&basic_filter<I, O>::basic_process, this)),
_output(new output_obj<O, basic_filter<I, O> >()) {}
As you can see, I'm passing this (which should be a plain pointer that gcc should copy on the stack imo) and gcc isn't reading the const that is behind the *, then to complain it isn't there.

Am I doing something wrong or is it not me?


Oh, add to that that the error only appears (and apparently is a problem) when I create a constructor in the subclass. The constructor is empty for practical purposes and doesn't explicitly call the parent constructor (same as a default constructor would).
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:G++ + C++ problem with const

Post by Candy »

Ok, got it solved. There were a load of errors in the file (the one here was that I had a parameter mismatch I didn't see because of all the template muck) which the compiler apparently didn't consider worth compiling even though it was the base class even without constructor.
Post Reply