Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: operator () overloading. Pin
Russell'22-Feb-06 23:22
Russell'22-Feb-06 23:22 
GeneralRe: operator () overloading. Pin
9ine23-Feb-06 1:55
9ine23-Feb-06 1:55 
AnswerRe: operator () overloading. Pin
toxcct22-Feb-06 23:22
toxcct22-Feb-06 23:22 
AnswerRe: operator () overloading. Pin
9ine23-Feb-06 1:03
9ine23-Feb-06 1:03 
GeneralRe: operator () overloading. Pin
9ine23-Feb-06 1:01
9ine23-Feb-06 1:01 
GeneralRe: operator () overloading. Pin
BadKarma23-Feb-06 3:44
BadKarma23-Feb-06 3:44 
GeneralRe: operator () overloading. Pin
9ine23-Feb-06 5:26
9ine23-Feb-06 5:26 
GeneralRe: operator () overloading. Pin
BadKarma23-Feb-06 8:29
BadKarma23-Feb-06 8:29 
Hi,

I think there is a flaw in your concept:

I believe you would like to use the following syntaxis:
MyArr arr;

// get long double for persision calc
long double ldData = arr(1);

// heavy calculation :laugh:
ldata *= 2;

// store modified data
arr(1) = lData;

For the first arr(1) you only need a right value
long double operator()(int x)
{
  return static_cast<long double>(sdata[x]);
}
but for the second arr(1) you need a left value
short& operator()(int x)
{
  return sdata[x];
}


The compiler can't decide which to use:

You can't combine the two functions like this :
long double& operator()(int x)
{
  return (long double&)sdata[x];
}
because the data allignment will be fault.

I think you best use a get (returning a long double) and a set (setting a short).

There is a solution with templates but you might (I certanly do Laugh | :laugh: ) consider it to be worse
class arr
{
public:
  arr() {
    pData = new short[5];
    for(short sIndex = 0; sIndex < 5; sIndex++)
      pData[sIndex] = sIndex;
  }

  template<typename T>
  T operator()(int x)
  {
    return static_cast<T>(pData[x]);
  }

  short& operator()(int x)
  {
    return *(pData + x);
  }

  short* pData;
};

int _tmain(int argc, _TCHAR* argv[])
{
  arr a;

  double long lData = a.operator()<double long>(1);

  lData *= 2;

  a(1) = static_cast<short>(lData);

	return 0;
}


codito ergo sum
QuestionCrystal Reports 11 with visual Studio .NET Pin
Irfan Shahid23-Feb-06 1:04
Irfan Shahid23-Feb-06 1:04 
QuestionRe: operator () overloading. Pin
David Crow23-Feb-06 3:41
David Crow23-Feb-06 3:41 
AnswerRe: operator () overloading. Pin
9ine23-Feb-06 5:18
9ine23-Feb-06 5:18 
GeneralRe: operator () overloading. Pin
David Crow23-Feb-06 5:45
David Crow23-Feb-06 5:45 
GeneralRe: operator () overloading. Pin
9ine23-Feb-06 22:59
9ine23-Feb-06 22:59 
GeneralRe: operator () overloading. Pin
David Crow24-Feb-06 2:42
David Crow24-Feb-06 2:42 
GeneralRe: operator () overloading. Pin
9ine24-Feb-06 3:00
9ine24-Feb-06 3:00 
QuestionRe: operator () overloading. Pin
David Crow24-Feb-06 3:08
David Crow24-Feb-06 3:08 
AnswerRe: operator () overloading. Pin
9ine25-Feb-06 1:08
9ine25-Feb-06 1:08 
GeneralRe: operator () overloading. Pin
jhwurmbach23-Feb-06 22:20
jhwurmbach23-Feb-06 22:20 
GeneralRe: operator () overloading. Pin
9ine23-Feb-06 22:53
9ine23-Feb-06 22:53 
GeneralRe: operator () overloading. Pin
jhwurmbach23-Feb-06 23:24
jhwurmbach23-Feb-06 23:24 
AnswerRe: operator () overloading. Pin
Wim Engberts23-Feb-06 5:47
Wim Engberts23-Feb-06 5:47 
JokeRe: operator () overloading. Pin
jhwurmbach23-Feb-06 22:21
jhwurmbach23-Feb-06 22:21 
QuestionStarting a process in the background no console Pin
theprinc22-Feb-06 23:00
theprinc22-Feb-06 23:00 
AnswerRe: Starting a process in the background no console Pin
Nibu babu thomas22-Feb-06 23:04
Nibu babu thomas22-Feb-06 23:04 
GeneralRe: Starting a process in the background no console Pin
theprinc22-Feb-06 23:21
theprinc22-Feb-06 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.