"Eric Lilja" <mi****************************@gmail.com> wrote in message
news:d4**********@news.island.liu.se...
Hello, I recently saw code like this:
$ cat t.h
namespace nc{
template<typename T>
class Base {
T hello;
protected:
int test1;
};
template<typename T>
class Next: public Base<T>{
You really want the following to be a private member?
int test();
};
};
No semi-colon required above.
#include "t.tmpl"
$ cat t.tmpltemplate<typename T>
int nc::Next<T>::test(){
return test1;
Change the above to:
return this->test1;
or
return Base<T>::test1;
For more details on why you need to do this, see:
http://www.parashift.com/c++-faq-lit...html#faq-35.12
}
I couldn't even get the code to compile until I'd changed return test1;
toreturn Base<T>test1;"t.tmpl" looks like a renamed source (.cpp) file and
return Base<T>::test1;
//you missed the "::" part
it's used to work around the fact that the compilerlacks the export
keyword but the author still wantsto hide the implementation details. I
immediatelythought this was ugly indeed, was I right? If so, why?/ Eric
Personally, I find it ugly too. But the lack of an export keyword in most
compilers is the reason why people have to do this (or something similar to
this).
You may also find Q7 to Q9 helpful:
http://www.parashift.com/c++-faq-lite/templates.html
Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>