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

Discussion in 'C++' started by Eric Lilja, Apr 29, 2005.

  1. Eric Lilja

    Eric Lilja Guest

    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
     
    Eric Lilja, Apr 29, 2005
    #1
    1. Advertising

  2. Eric Lilja

    Eric Lilja Guest

    oops, sorry, I don't know what happened to my line breaks.

    / Eric
     
    Eric Lilja, Apr 29, 2005
    #2
    1. Advertising

  3. Eric Lilja

    Sumit Rajan Guest

    "Eric Lilja" <> wrote in message
    news:d4s1pu$k0n$...
    > 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-lite/templates.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 <>
     
    Sumit Rajan, Apr 29, 2005
    #3
  4. Eric Lilja

    Sumit Rajan Guest

    "Sumit Rajan" <> wrote in message
    news:...
    > 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 <>
     
    Sumit Rajan, Apr 29, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce W...1

    Can a .aspx file be renamed to .htm?

    Bruce W...1, Aug 23, 2003, in forum: ASP .Net
    Replies:
    11
    Views:
    685
    MS News \(MS ILM\)
    Aug 24, 2003
  2. Brent White
    Replies:
    4
    Views:
    2,295
    Brent
    Oct 28, 2005
  3. Stephen
    Replies:
    1
    Views:
    439
    Stephen
    Jan 13, 2006
  4. ultr
    Replies:
    2
    Views:
    545
  5. Amarpal
    Replies:
    2
    Views:
    870
    harsha
    Dec 31, 2011
Loading...

Share This Page