[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: C++ template question.
From:       Esben Mose Hansen <kde () mosehansen ! dk>
Date:       2005-02-27 19:32:23
Message-ID: 200502272031.16213.kde () mosehansen ! dk
[Download RAW message or body]

On Sunday 2005-02-27 19:11, Jonas Widarsson wrote:

> B:
>
> I have two books available:
> printed: Bjarne Stroustrup - The C++ Programming Language Special Edition
> online: Frank B. Brokken  - http://www.icce.rug.nl/documents/cplusplus/
>
> They both cover template functions and template classes. Still, I get lost
> in them while trying to find out if these concepts can legally be combined.

Yes, good only template guides are not easy to come by, and B. Stroustrup's 
book is not the best of introductions. There is a book called something like 
"The complete template reference" which is good, if extremely dry. I can give 
you the ISBN if you'd like. It's $60 or so :-/

>
> Here's what I would like to do:
>
> ********************* oscillatorbase.h START
> #ifndef OSCILLATORBASE_H
> #define OSCILLATORBASE_H
>
> /**
> Base class for creating oscillators
> @author Jonas Widarsson
>  */
>
> class OscillatorBase{
>
>  public:
>     OscillatorBase();
>     ~OscillatorBase();
>     template< typename SampleType>
>       void fillBuffer( SampleType *buffer, const unsigned &nframes, const
> int &sampleFreq);
> };

If fillBuffer does what I think it does, you would be better of by something 
like

template<typename BufferIt>
fillBuffer( BufferIt begin, BufferIt end, const int sampleFreq)



> C:
>
> So I start wondering. Is my use of templates illegal?

They are fine. I fell into this trap the first time, too :)

> I mean, people talk about template functions and template classes.
> My OscillatorBase::fillBuffer() code is supposed to be a template function
> within an ordinary class. Is that a design error?

No, that's perfectly fine, but I would use the iterator concept instead of the 
buffer thing you have now. Assume your iterator can do "it++" --- then 
clients can use raw pointers as iterators with no problems.

Feel free to email me in private for further discussions of this.

-- 
regards. Esben
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic