473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What do you call this construct?

joe
Curious if this type of construct has a name, or is a recognized
design pattern:

class Function
{
public:
Function() { // do loads of work here in the Constructor, store result
in m_result }

operator double() { return m_result;} //Automatic Type Conversion

private:
double m_result;
};

with the expected simple usage:

double value = Function();

Is there some recognized caveat to the above? I don't see it used
very often.

Feb 27 '07 #1
4 1279
joe wrote:
Curious if this type of construct has a name, or is a recognized
design pattern:

class Function
{
public:
Function() { // do loads of work here in the Constructor, store result
in m_result }

operator double() { return m_result;} //Automatic Type Conversion

private:
double m_result;
};

with the expected simple usage:

double value = Function();

Is there some recognized caveat to the above? I don't see it used
very often.
What's the advantage of that class implementation over, say,

double Function() {
double _result;
// do loads of work here, store the result in _result
return _result;
}

? I don't see any in your code. And the syntax looks pretty much
like a function call, so it would be very confusing to somebody
reading the code to learn that 'Function' is not a function at all.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 27 '07 #2
joe wrote:
Curious if this type of construct has a name, or is a recognized
design pattern:

class Function
{
public:
Function() { // do loads of work here in the Constructor, store result
in m_result }

operator double() { return m_result;} //Automatic Type Conversion

private:
double m_result;
};

with the expected simple usage:

double value = Function();

Is there some recognized caveat to the above? I don't see it used
very often.
I guess it could be called the "abuse of a class" pattern.

--
Ian Collins.
Feb 27 '07 #3
Ian Collins wrote:
>
I guess it could be called the "abuse of a class" pattern.
You need to add it to the antipattern list since you coined it :)

http://en.wikipedia.org/wiki/Antipattern
Feb 27 '07 #4
On Feb 27, 12:59 pm, Piyo <cybermax...@yahoo.comwrote:
Ian Collins wrote:
I guess it could be called the "abuse of a class" pattern.
Without going into "it is a bad idea to do", I would refer you to
TCPL, 3rd Ed. S11.4.
It is a way to do type conversion.

Feb 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Reinhold Birkenfeld | last post by:
Hello, I know that there are different YAML engines for Python out there (Syck, PyYaml, more?). Which one do you use, and why? For those of you who don't know what YAML is: visit...
13
by: gtux | last post by:
Hi everybody: I'm new in Javascript, I found some code and there is this: var fruit = { 'apple' : { 'weight' : 10, 'cost' : 9}, 'peach' : { 'weight' : 19, 'cost' : 10} }
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
7
by: arun_shamli | last post by:
class CDate { public: CDate() {} CDate(const CDate& date) {} }; CDate function1() { CDate date(); return date;
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: golubovsky | last post by:
Hi, Is there an easy way to construct a function call out of a function and an array of actual arguments? e. g. given a function `fun' and an array I need to obtain equivalent of...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
13
by: shsingh | last post by:
I have a class A containing some map as data variables. I creat an object of class A on heap by allocatiing memory by using "malloc". This will return me the required memory but the object is not...
22
by: Nehil | last post by:
Does C follow call by value convention or call by reference? i see that there is nothing like reference in C standard but it is referenced. still, what should be the answer for the above...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.