avoiding object files

Discussion in 'C++' started by Alexander Stippler, Oct 10, 2004.

  1. Hello,

    I have written a little library which consists of template functions and
    classes (99%) and two non-template classes. I'd appreciate very much if I
    could use the library by only including some header files without having to
    deal with building and linking a library or object files. Are there any
    tricks how this can be achieved?
    I guess not, but perhaps you know better.

    Best regards,
    alex
     
    Alexander Stippler, Oct 10, 2004
    #1
    1. Advertising

  2. Alexander Stippler wrote in news:-ulm.de in
    comp.lang.c++:

    > Hello,
    >
    > I have written a little library which consists of template functions
    > and classes (99%) and two non-template classes. I'd appreciate very
    > much if I could use the library by only including some header files
    > without having to deal with building and linking a library or object
    > files. Are there any tricks how this can be achieved?
    > I guess not, but perhaps you know better.
    >


    Instead of

    class non_template
    {
    // whatever
    };

    Do:

    template < typename = void >
    class for_non_template
    {
    // Whatever (as above).
    };

    typedef for_non_template<> non_template;

    HTH.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
     
    Rob Williscroft, Oct 10, 2004
    #2
    1. Advertising

  3. Rob Williscroft wrote:

    > Alexander Stippler wrote in news:-ulm.de in
    > comp.lang.c++:
    >
    > > Hello,
    > >
    > > I have written a little library which consists of template functions
    > > and classes (99%) and two non-template classes. I'd appreciate very
    > > much if I could use the library by only including some header files
    > > without having to deal with building and linking a library or object
    > > files. Are there any tricks how this can be achieved?
    > > I guess not, but perhaps you know better.
    > >

    >
    > Instead of
    >
    > class non_template
    > {
    > // whatever
    > };
    >
    > Do:
    >
    > template < typename = void >
    > class for_non_template
    > {
    > // Whatever (as above).
    > };
    >
    > typedef for_non_template<> non_template;


    what does it mean if you use the typename keyword in a template parameter
    declaration?

    Thanks,

    David
     
    David Lindauer, Oct 10, 2004
    #3
  4. David Lindauer wrote in news: in
    comp.lang.c++:

    >
    > what does it mean if you use the typename keyword in a template parameter
    > declaration?
    >


    Its exactly the same as when you use class.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
     
    Rob Williscroft, Oct 10, 2004
    #4
  5. Rob Williscroft wrote:

    > Alexander Stippler wrote in news:-ulm.de in
    > comp.lang.c++:
    >
    >> Hello,
    >>
    >> I have written a little library which consists of template functions
    >> and classes (99%) and two non-template classes. I'd appreciate very
    >> much if I could use the library by only including some header files
    >> without having to deal with building and linking a library or object
    >> files. Are there any tricks how this can be achieved?
    >> I guess not, but perhaps you know better.
    >>

    >
    > Instead of
    >
    > class non_template
    > {
    > // whatever
    > };
    >
    > Do:
    >
    > template < typename = void >
    > class for_non_template
    > {
    > // Whatever (as above).
    > };
    >
    > typedef for_non_template<> non_template;
    >
    > HTH.
    >
    > Rob.


    That works fine for whole classes, but what about simple objects. I have
    only one global variable, which I do not want to give any dummy template
    parameter. Just an instantiation of a non-template class. It's only this one
    object which forces the creation of a library. Any workaround?

    regards,
    alex
     
    Alexander Stippler, Oct 11, 2004
    #5
  6. Alexander Stippler

    Lionel B Guest

    Alexander Stippler wrote:
    > /snip/
    >
    > ... I have only one global variable, which I do not want
    > to give any dummy template parameter. Just an instantiation
    > of a non-template class. It's only this one object which
    > forces the creation of a library. Any workaround?


    Well, you could declare your global variable "extern" in the header and
    demand that the *user* of the library define it somewhere.
    Regards,

    --
    Lionel B
     
    Lionel B, Oct 13, 2004
    #6
  7. Alexander Stippler wrote in news:-ulm.de in
    comp.lang.c++:

    > Rob Williscroft wrote:
    >
    >> Alexander Stippler wrote in news:-ulm.de in
    >> comp.lang.c++:
    >>
    >>> Hello,
    >>>
    >>> I have written a little library which consists of template functions
    >>> and classes (99%) and two non-template classes. I'd appreciate very
    >>> much if I could use the library by only including some header files
    >>> without having to deal with building and linking a library or object
    >>> files. Are there any tricks how this can be achieved?
    >>> I guess not, but perhaps you know better.
    >>>

    >>
    >> Instead of
    >>
    >> class non_template
    >> {
    >> // whatever
    >> };
    >>
    >> Do:
    >>
    >> template < typename = void >
    >> class for_non_template
    >> {
    >> // Whatever (as above).
    >> };
    >>
    >> typedef for_non_template<> non_template;
    >>
    >> HTH.
    >>
    >> Rob.

    >
    > That works fine for whole classes, but what about simple objects. I
    > have only one global variable, which I do not want to give any dummy
    > template parameter. Just an instantiation of a non-template class.
    > It's only this one object which forces the creation of a library. Any
    > workaround?
    >



    inline non_template &object()
    {
    static non_template obj = non_template();
    return obj;
    }


    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
     
    Rob Williscroft, Oct 13, 2004
    #7
  8. Rob Williscroft wrote:

    > Alexander Stippler wrote in news:-ulm.de in
    > comp.lang.c++:
    >
    >> Rob Williscroft wrote:
    >>
    >>> Alexander Stippler wrote in news:-ulm.de in
    >>> comp.lang.c++:
    >>>
    >>>> Hello,
    >>>>
    >>>> I have written a little library which consists of template functions
    >>>> and classes (99%) and two non-template classes. I'd appreciate very
    >>>> much if I could use the library by only including some header files
    >>>> without having to deal with building and linking a library or object
    >>>> files. Are there any tricks how this can be achieved?
    >>>> I guess not, but perhaps you know better.
    >>>>
    >>>
    >>> Instead of
    >>>
    >>> class non_template
    >>> {
    >>> // whatever
    >>> };
    >>>
    >>> Do:
    >>>
    >>> template < typename = void >
    >>> class for_non_template
    >>> {
    >>> // Whatever (as above).
    >>> };
    >>>
    >>> typedef for_non_template<> non_template;
    >>>
    >>> HTH.
    >>>
    >>> Rob.

    >>
    >> That works fine for whole classes, but what about simple objects. I
    >> have only one global variable, which I do not want to give any dummy
    >> template parameter. Just an instantiation of a non-template class.
    >> It's only this one object which forces the creation of a library. Any
    >> workaround?
    >>

    >
    >
    > inline non_template &object()
    > {
    > static non_template obj = non_template();
    > return obj;
    > }
    >
    >
    > Rob.


    Works in general. But this way I have a function call, not direct access. In
    my special situation direct access to the variable is necessary. It is
    called '_' and I want to use it for function arguments in special
    situations, like A( _ , 1 ) and not A( _(), 1). Thus your solution does not
    work for me. I'm afraid, IMO there is no solution.

    regards,
    alex
     
    Alexander Stippler, Oct 14, 2004
    #8
  9. Alexander Stippler

    Lionel B Guest

    Alexander Stippler <-ulm.de> wrote in message news:<-ulm.de>...
    > Rob Williscroft wrote:
    >
    > > Alexander Stippler wrote in news:-ulm.de in
    > > comp.lang.c++:
    > >
    > >> Rob Williscroft wrote:
    > >>
    > >>> Alexander Stippler wrote in news:-ulm.de in
    > >>> comp.lang.c++:
    > >>>
    > >>>> Hello,
    > >>>>
    > >>>> I have written a little library which consists of template functions
    > >>>> and classes (99%) and two non-template classes. I'd appreciate very
    > >>>> much if I could use the library by only including some header files
    > >>>> without having to deal with building and linking a library or object
    > >>>> files. Are there any tricks how this can be achieved?
    > >>>> I guess not, but perhaps you know better.


    /snip/

    > >> I have only one global variable, which I do not want to give any dummy
    > >> template parameter. Just an instantiation of a non-template class.
    > >> It's only this one object which forces the creation of a library. Any
    > >> workaround?
    > >>

    > >
    > > inline non_template &object()
    > > {
    > > static non_template obj = non_template();
    > > return obj;
    > > }
    > >
    > >
    > > Rob.


    That's neat :)

    > Works in general. But this way I have a function call, not direct access. In
    > my special situation direct access to the variable is necessary. It is
    > called '_' and I want to use it for function arguments in special
    > situations, like A( _ , 1 ) and not A( _(), 1). Thus your solution does not
    > work for me. I'm afraid, IMO there is no solution.


    What exactly is the problem with declaring your object "extern"?

    Regards,

    --
    Lionel B
     
    Lionel B, Oct 15, 2004
    #9
  10. Lionel B wrote:

    > Alexander Stippler <-ulm.de> wrote in message
    > news:<-ulm.de>...
    >> Rob Williscroft wrote:
    >>
    >> > Alexander Stippler wrote in news:-ulm.de in
    >> > comp.lang.c++:
    >> >
    >> >> Rob Williscroft wrote:
    >> >>
    >> >>> Alexander Stippler wrote in news:-ulm.de in
    >> >>> comp.lang.c++:
    >> >>>
    >> >>>> Hello,
    >> >>>>
    >> >>>> I have written a little library which consists of template functions
    >> >>>> and classes (99%) and two non-template classes. I'd appreciate very
    >> >>>> much if I could use the library by only including some header files
    >> >>>> without having to deal with building and linking a library or object
    >> >>>> files. Are there any tricks how this can be achieved?
    >> >>>> I guess not, but perhaps you know better.

    >
    > /snip/
    >
    >> >> I have only one global variable, which I do not want to give any dummy
    >> >> template parameter. Just an instantiation of a non-template class.
    >> >> It's only this one object which forces the creation of a library. Any
    >> >> workaround?
    >> >>
    >> >
    >> > inline non_template &object()
    >> > {
    >> > static non_template obj = non_template();
    >> > return obj;
    >> > }
    >> >
    >> >
    >> > Rob.

    >
    > That's neat :)
    >
    >> Works in general. But this way I have a function call, not direct access.
    >> In my special situation direct access to the variable is necessary. It is
    >> called '_' and I want to use it for function arguments in special
    >> situations, like A( _ , 1 ) and not A( _(), 1). Thus your solution does
    >> not work for me. I'm afraid, IMO there is no solution.

    >
    > What exactly is the problem with declaring your object "extern"?
    >
    > Regards,
    >


    We want to achieve the most simple way of usage for our library since users
    are students with very poor knowledge of C++ and software development at
    all. They shall do numerical exercises with it (and have already done
    successfully one semester).
    Declaring '_' as extern would require the user to define it somewhere. On
    the other hand this tiny little '_' object is a really nice piece of
    syntactic sugar, we do not want to miss anymore. But it's also the one
    single piece of code which prevents us from having the whole library to be
    used by including headers only.

    regards,
    alex
     
    Alexander Stippler, Oct 15, 2004
    #10
  11. Alexander Stippler

    Lionel B Guest

    Alexander Stippler <-ulm.de> wrote in message news:<-ulm.de>...
    > Lionel B wrote:
    > > Alexander Stippler <-ulm.de> wrote in message
    > > news:<-ulm.de>...


    /snip/

    > >> >> I have only one global variable, which I do not want to give any dummy
    > >> >> template parameter. Just an instantiation of a non-template class.
    > >> >> It's only this one object which forces the creation of a library. Any
    > >> >> workaround?


    /snip/

    > >> In my special situation direct access to the variable is necessary. It is
    > >> called '_' and I want to use it for function arguments in special
    > >> situations, like A( _ , 1 ) and not A( _(), 1). Thus your solution does
    > >> not work for me. I'm afraid, IMO there is no solution.

    > >
    > > What exactly is the problem with declaring your object "extern"?
    > >

    > We want to achieve the most simple way of usage for our library since users
    > are students with very poor knowledge of C++ and software development at
    > all. They shall do numerical exercises with it (and have already done
    > successfully one semester).


    Fair enough.

    > Declaring '_' as extern would require the user to define it somewhere. On
    > the other hand this tiny little '_' object is a really nice piece of
    > syntactic sugar, we do not want to miss anymore. But it's also the one
    > single piece of code which prevents us from having the whole library to be
    > used by including headers only.


    I have to confess that having a variable called '_' sounds to me like
    a recipe for generating fabulously opaque compiler errors (especially
    for "students with very poor knowledge of C++" ...?).

    That said, surely even the most computer-illiterate student could be
    persuaded to copy-and-paste the line:

    underscore_object_type _;

    into a source file? Perhaps they might be enticed with:

    #define MY_TEACHER_TOLD_ME_TO_PUT_THIS_HERE underscore_object_type _;

    ;)

    --
    Lionel B
     
    Lionel B, Oct 15, 2004
    #11
    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. Christian Seberino
    Replies:
    4
    Views:
    497
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Oct 9, 2003
  2. Stefan Schwarzer
    Replies:
    0
    Views:
    400
    Stefan Schwarzer
    Feb 8, 2006
  3. Bob Nelson

    UB? Avoiding ``object'' before array's start

    Bob Nelson, Jul 25, 2006, in forum: C Programming
    Replies:
    11
    Views:
    406
    Joe Wright
    Jul 27, 2006
  4. Öö Tiib
    Replies:
    6
    Views:
    300
    Öö Tiib
    Aug 11, 2010
  5. Adam Markiewicz

    Avoiding copying of an object

    Adam Markiewicz, Sep 26, 2010, in forum: C++
    Replies:
    4
    Views:
    414
    Carfield Yim
    Sep 27, 2010
Loading...

Share This Page