468,720 Members | 1,907 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

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

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
3 1124
oops, sorry, I don't know what happened to my line breaks.

/ Eric
Jul 23 '05 #2

"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

"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.

Similar topics

1 post views Thread by Andres Baravalle | last post: by
6 posts views Thread by Al-Burak | last post: by
10 posts views Thread by Ben Sehara | last post: by
7 posts views Thread by =?Utf-8?B?UGV0ZXI=?= | last post: by
8 posts views Thread by squaretriangle | last post: by
2 posts views Thread by Cameron.MacNeil.024 | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.