The best OOP languages??

D

Dave Rahardja

Let's compare your example to the "wrapper"-method:

extern "C" void OpenResource();
extern "C" void CloseResource();

/* ... */

class CResource
{
public:
CResource() { OpenResource(); }
~CResource(){ CloseResource(); }
}

void fn()
{
CResource r;
ExceptionThrowingCPPFunction();
}

Writing that one wrapper class once certainly seemed to pay off. Also,
the wrapper solution is reusable - available everywhere you use the
CResource.

Oh, I know. The example I gave was a trivial one. Some of the libraries I've
used have dozens of functions to manipulate some internal state, and must be
encapsulated by the dozen, which is a pain.

But you're right that once we do it we can reuse it for the next go-round.

-dr
 
R

Roland Pibinger

Let's compare your example to the "wrapper"-method:

extern "C" void OpenResource();
extern "C" void CloseResource();

/* ... */

class CResource
{
public:
CResource() { OpenResource(); }
~CResource(){ CloseResource(); }

private:
CResource(const CResource&);
CResource& operator=(const CResource&);
};

void fn()
{
CResource r;
ExceptionThrowingCPPFunction();
}

Writing that one wrapper class once certainly seemed to pay off. Also,
the wrapper solution is reusable - available everywhere you use the
CResource.

Totally agreed (if implemented correctly)!

Best wishes,
Roland Pibinger
 
P

peter.koch.larsen

Roland said:
private:
CResource(const CResource&);
CResource& operator=(const CResource&);


Totally agreed (if implemented correctly)!

Right. It was a quick and dirty job (I also forgot a semi-colon, which
mysteriously popped up in your quote).
In productioncode, I would actually have used

class CResource: not_copyable

where not_copyable is a small class that simply turns off the copy
constructor and assignment operator.
Best wishes,
Roland Pibinger

Kind regards
Peter Koch Larsen
 
J

j

I always liked Delphi. A great RAD tool, and easy to learn.

But, I get paid a lot more to do c++ work, so guess which I'm using
now...?


C++ if you want a good flexible career, Smalltalk if you want to have fun
at it...if you can find a job
 
A

Avoid normal situations.

Stewart Gordon said:
John Swan wrote:
You mean it can run on your washing machine? :)

Hey, it works on mine.

--
alt.flame Special Forces
"Democracy is that system of government under which the people, having 35,717,
342 native-born adult whites to choose from, including thousands who are
handsome and many who are wise, pick out a Coolidge to be head of the States."
-- H. L. Mencken, _Prejudices_, Fifth Series, 1926
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top