Re: Novice - Advice required
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 14 Jul 2005 10:16:56 +0100
"David++" <David@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0BD14C22-7286-4D6C-BCCE-10F9E260E143@xxxxxxxxxxxxxxxx
> Due to its size I would like to write this function into a new
> class (?) in
> a seperate .cpp file (or header file?) and then whenever I want to
> use the
> function I would create an object of this class, initialize it
> with the
> value, do the computation, return the result and then destroy the
> object. Is
> this the best approach for this task?
"Best" is a value judgement which only you can make.
But in principle there is nothing wrong with classes whose purpose
is just to perform certain tasks.
> Further, would it be best define the class in a cpp file or in a
> header file
> and then 'include' the header file which defines the class?
Usually you define the class in a .h file and implement its member
functions in a .cpp file which includes the .h file.
So file "xyz.h" would contain
class XYZ
{
public
int doTask( int x );
};
and "xyz.cpp" would contain
#include "xyz.h"
int XYX::doTask( int x )
{
//.......................
}
The place where doTask() is called from also needs to include
xyz.h.
Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm
.
- Follow-Ups:
- Re: Novice - Advice required
- From: David++
- Re: Novice - Advice required
- References:
- Novice - Advice required
- From: David++
- Novice - Advice required
- Prev by Date: Re: function pointer "term does not evaluate to a function"
- Next by Date: Re: Novice - Advice required
- Previous by thread: Novice - Advice required
- Next by thread: Re: Novice - Advice required
- Index(es):
Relevant Pages
|
Loading