By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,711 Members | 2,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,711 IT Pros & Developers. It's quick & easy.

Including a (renamed) source file is ugly, right?

P: n/a
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>{

int test();
};
};

#include "t.tmpl"
$ cat t.tmpltemplate<typename T>
int nc::Next<T>::test(){
return test1;
}
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
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
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
oops, sorry, I don't know what happened to my line breaks.

/ Eric
Jul 23 '05 #2

P: n/a

"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>
Jul 23 '05 #3

P: n/a

"Sumit Rajan" <su*********@gmail.com> wrote in message
news:3d*************@individual.net...
But the lack of an export keyword in most compilers


Let me try to rephrase that:

But the fact that most compilers have not (yet) implemented support for the
export keyword ...

Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.