Problem with templates (is this correct code?)

massacre@quake2.nettally.com massacre@quake2.nettally.com
Tue Sep 7 18:41:00 GMT 1999


I seem to be having a problem getting my template to recognize adding a
'const' keyword to a function. Here is some much-simplified example code:

template <class classType>
class test{
public:
        int lookup(const classType);
};

template <class classType>
int test<classType>::lookup(const classType)
{ return 0; }

typedef test<char *> mytest;
int main(){
        mytest *foo=new mytest();
        const char * bar="this should work, right?";
        foo->lookup(bar);
        return 0;
}

gives:

a.cc: In function `int main()':
a.cc:16: passing `const char *' as argument 1 of `test<char*>::lookup(char*)'
discards qualifiers

gcc version 2.95.1 19990816 (release)

-David Waite (not on mailing list, please reply via email)



More information about the Gcc-bugs mailing list