CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 24

Threaded View

  1. #1
    Join Date
    Aug 2002
    Location
    Hamburg / Germany
    Posts
    280

    Question Mathematical problem with a template

    Hi,
    I have this template
    Code:
    template <class T> class dimensions
    {
      protected:
        T m_xstart;
        T m_xend;
        T m_ystart;
        T m_yend;
    
      public:
       inline T getxstart(){return m_xstart;}
       inline T getxend(){return m_xend;}
       inline T getystart(){return m_ystart;}
       inline T getyend(){return m_yend;}
    
       inline void setxstart(T xstart){m_xstart = xstart;}
       inline void setxend(T xend){m_xend = xend;}
       inline void setystart(T ystart){m_ystart = ystart;}
       inline void setyend(T yend){m_yend = yend;}
    
       inline double getaspectratio()
       {
         T width = m_xend - m_xstart;
         T height = m_yend - m_ystart;
    
         if (height)
           return width / height;}
    };
    Now if I do the following:
    Code:
      dimensions<double> dim;
      dim.setxstart(0);
      dim.setxend(500);
      dim.setystart(0);
      dim.setyend(1000);
    
      double ratio = dim.getaspectratio();
    "ratio" is allways zero. I expect it to be 0.5. Why is this?

    Thanks in advance

    Juergen
    Last edited by AlionSolutions; December 11th, 2006 at 07:40 PM. Reason: Typo

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