Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > avoiding object files

Reply
Thread Tools

avoiding object files

 
 
Alexander Stippler
Guest
Posts: n/a
 
      10-10-2004
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
 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      10-10-2004
Alexander Stippler wrote in news:(E-Mail Removed)-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/
 
Reply With Quote
 
 
 
 
David Lindauer
Guest
Posts: n/a
 
      10-10-2004


Rob Williscroft wrote:

> Alexander Stippler wrote in news:(E-Mail Removed)-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
 
Reply With Quote
 
Rob Williscroft
Guest
Posts: n/a
 
      10-10-2004
David Lindauer wrote in news:(E-Mail Removed) 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/
 
Reply With Quote
 
Alexander Stippler
Guest
Posts: n/a
 
      10-11-2004
Rob Williscroft wrote:

> Alexander Stippler wrote in news:(E-Mail Removed)-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
 
Reply With Quote
 
Lionel B
Guest
Posts: n/a
 
      10-13-2004
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

 
Reply With Quote
 
Rob Williscroft
Guest
Posts: n/a
 
      10-13-2004
Alexander Stippler wrote in news:(E-Mail Removed)-ulm.de in
comp.lang.c++:

> Rob Williscroft wrote:
>
>> Alexander Stippler wrote in news:(E-Mail Removed)-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/
 
Reply With Quote
 
Alexander Stippler
Guest
Posts: n/a
 
      10-14-2004
Rob Williscroft wrote:

> Alexander Stippler wrote in news:(E-Mail Removed)-ulm.de in
> comp.lang.c++:
>
>> Rob Williscroft wrote:
>>
>>> Alexander Stippler wrote in news:(E-Mail Removed)-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

 
Reply With Quote
 
Lionel B
Guest
Posts: n/a
 
      10-15-2004
Alexander Stippler <(E-Mail Removed)-ulm.de> wrote in message news:<(E-Mail Removed)-ulm.de>...
> Rob Williscroft wrote:
>
> > Alexander Stippler wrote in news:(E-Mail Removed)-ulm.de in
> > comp.lang.c++:
> >
> >> Rob Williscroft wrote:
> >>
> >>> Alexander Stippler wrote in news:(E-Mail Removed)-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
 
Reply With Quote
 
Alexander Stippler
Guest
Posts: n/a
 
      10-15-2004
Lionel B wrote:

> Alexander Stippler <(E-Mail Removed)-ulm.de> wrote in message
> news:<(E-Mail Removed)-ulm.de>...
>> Rob Williscroft wrote:
>>
>> > Alexander Stippler wrote in news:(E-Mail Removed)-ulm.de in
>> > comp.lang.c++:
>> >
>> >> Rob Williscroft wrote:
>> >>
>> >>> Alexander Stippler wrote in news:(E-Mail Removed)-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoiding copying of an object Adam Markiewicz C++ 4 09-27-2010 06:07 PM
Re: Avoiding destruction of object Öö Tiib C++ 6 08-11-2010 08:47 PM
UB? Avoiding ``object'' before array's start Bob Nelson C Programming 11 07-27-2006 09:58 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
C extension question about avoiding memory leaks with the object returned... Christian Seberino Python 4 10-09-2003 04:25 AM



Advertisments