CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Posts
    14

    Multiply Operator for a CTimeSpan object?

    Sorry if this is a dumb question.

    I have a CTimeSpan object that represents the period of time that I want an experiment to run. I then want to be able to run the experiment again for a factor * (CTimeSpan object).

    Unfortunately there is no muliplication operator for CTimeSpan objects, so does anyone know a simple way to achieve the same goal ?, i.e. multiply a CTimeSpan by a float value.

    As you have guessed I am a novice. Any help woudl be great.

    WynW

  2. #2
    Join Date
    May 2002
    Location
    Poland
    Posts
    48
    You have to do something like this:
    Code:
    int sec = timespan.GetTotalSeconds();
    sec = (int)(sec * 10.5);
    timespan = CTimeSpan((time_t)sec);
    regards,
    MiMec

  3. #3
    Join Date
    May 2002
    Posts
    1,435
    You could create your own operator like this:

    CTimeSpan& operator *=(CTimeSpan& t, float n)
    {
    t = (time_t)(t.GetTotalSeconds() * n);
    return t;
    }

    CTimeSpan t1(1,24,60,60);
    t1 *= 2;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured