Book a Demo

Author Topic: How to reverse a templated class  (Read 2140 times)

ncostes

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
How to reverse a templated class
« on: November 06, 2007, 06:08:27 am »
For some reason the following class (or any like it) will not import. No errors are given, but no class is created by EA on import. I tried commenting out the fwd declarations of the class and friend, as well as the method implementations, to no avail. I tried generating from an identically named class first and then syncing, no good.
Thanks

#ifndef CORESIM_IO_POINT_H_INCLUDED
#define CORESIM_IO_POINT_H_INCLUDED

#include "Osal/Osal.h"

#include <iostream>
#include <vector>


namespace CoreSim
{
  namespace Io
  {
     // This is a forward declaration of the class so that we can declare the friend
     // function. Don't use doxygen tags for these 2 here.
     template<class X, class Y>
     class Point;

     // Forward declaration for the friend function.
     template<class X, class Y>
     std::ostream &operator<<  (std::ostream& output,
                              const CoreSim::Io::Point<X, Y>& rhs);


     /** Point class. Represents a tuple of values, which can be scalar or vector
      * (or any type since this is a template class).
      */
     template <class X, class Y>
     class Point
     {
     public:
        /** Constructor.
         * @param x Initial value for X coordinate.
         * @param y Initial value for Y coordinate.
         */
        Point (X x, Y y);

        /** Constructor. */
        Point ();

        /** Destructor. */
        virtual ~Point();

        /** Accessor returns X
         * @return Value of X.
         */
        inline X getX();

        /** Accessor sets X.
         * @param x New value of x.
         */
        inline void setX (X x);

        /** Accessor returns Y
         * @return Value of Y.
         */
        inline Y getY();

        /** Accessor sets Y.
         * @param y New value of y.
         */
        inline void setY (Y y);


        /** Override the stream insertion operator so we can print the contents.
         * @return The output stream.
         * @param output Reference to the output stream.
         * @param rhs Right hand side of the stream insertion operator.
         */
        friend std::ostream &operator<< <> (std::ostream& output,
                                        const CoreSim::Io::Point<X, Y>& rhs);

     protected:
        /** X coordinate. */
        X m_x;

        /** Y coordinate. */
        Y m_y;

     };

     /********************** Method implementations. ***********************/

     template <class X, class Y>
     Point<X,Y>::Point (X x, Y y)
           : m_x(x),
           m_y(y)
     {}

     template <class X, class Y>
     Point<X,Y>::Point ()
     {}

     template <class X, class Y>
     Point<X,Y>::~Point()
     {}

     template <class X, class Y>
     inline X Point<X,Y>::getX()
     {
        return m_x;
     }

     template <class X, class Y>
     inline void Point<X,Y>::setX (X x)
     {
        m_x = x;
     }

     template <class X, class Y>
     inline Y Point<X,Y>::getY()
     {
        return m_y;
     }

     template <class X, class Y>
     inline void Point<X,Y>::setY (Y y)
     {
        m_y = y;
     }

     template <class X, class Y>
     std::ostream &operator<<(std::ostream& output,
                                     const CoreSim::Io::Point<X, Y>& rhs)
     {
        output << rhs.m_x << ", " << rhs.m_y  << std::endl;
        return output;
     }
  }
}

#endif
« Last Edit: November 06, 2007, 06:08:49 am by ncostes »

ncostes

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: How to reverse a templated class
« Reply #1 on: November 08, 2007, 02:54:19 pm »
The problem seems to be the friend function that is templated.

friend std::ostream &operator<< <> (std::ostream& output,
           const test::Point<X, Y>& rhs);

If I comment this out it reverses fine. But the weird <> notation is needed.
« Last Edit: November 08, 2007, 02:56:40 pm by ncostes »