Search Results

Search found 4 results on 1 pages for 'daclown'.

Page 1/1 | 1 

  • LaTeX command for last modified

    - by DaClown
    Is there a LaTeX command that prints the "last modified" date of the actual document? Since LaTeX projects consist of more than one file this command ideally prints the date of the actual file, not that of the project.

    Read the article

  • Type for use in template object to compare double values

    - by DaClown
    I got this n-dimensional point object: template <class T, unsigned int dimension> class Obj { protected: T coords[dimension]; static const unsigned int size = dimension; public: Obj() { }; Obj(T def) { for (unsigned int i = 0; i < size; ++i) coords[i]=def; }; Obj(const Obj& o) { for (unsigned int i = 0; i < size; ++i) coords[i] = o.coords[i]; } const Obj& operator= (const Obj& rhs) { if (this != &rhs) for (unsigned int i = 0; i < size; ++i) coords[i] = rhs.coords[i]; return *this; } virtual ~Obj() { }; T get (unsigned int id) { if (id >= size) throw std::out_of_range("out of range"); return coords[id]; } void set (unsigned int id, T t) { if (id >= size) throw std::out_of_range("out of range"); coords[id] = t; } }; and a 3D point class which uses Obj as base class: template <class U> class Point3DBase : public Obj<U,3> { typedef U type; public: U &x, &y, &z; public: Point3DBase() : x(Obj<U,3>::coords[0]), y(Obj<U,3>::coords[1]), z(Obj<U,3>::coords[2]) { }; Point3DBase(U def) : Obj<U,3>(def), x(Obj<U,3>::coords[0]), y(Obj<U,3>::coords[1]), z(Obj<U,3>::coords[2]) { }; Point3DBase(U x_, U y_, U z_) : x(Obj<U,3>::coords[0]), y(Obj<U,3>::coords[1]), z(Obj<U,3>::coords[2]) { x = x_; y = y_; z= z_; }; Point3DBase(const Point3DBase& other) : x(Obj<U,3>::coords[0]), y(Obj<U,3>::coords[1]), z(Obj<U,3>::coords[2]) { x = other.x; y = other.y; z = other.z; } // several operators ... }; The operators, basically the ones for comparison, use the simple compare-the-member-object approach like: virtual friend bool operator== (const Point3DBase<U> &lhs, const Point3DBase<U> rhs) { return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); } Then it occured to me that for the comparion of double values the simply equality approach is not very useful since double values should be compared with an error margin. What would be the best approach to introduce an error margin into the point? I thought about an epsDouble type as template parameter but I can't figure out how to achieve this.

    Read the article

  • What to return as an iterator when there is no container?

    - by DaClown
    I have an inheritance structure of objects with begin() and end() as pure virtual member functions in the base class. From this objects I'm planning to build a composite structure. This inner objects have std::vector member the begin() and end() get their data from. But in a leaf class there is no vector. Now I try to find a return value for begin() and end() in the leaf classes. What would be a good way to do that? The easiest way would be to have a vector member in the leaf classes with no elements in it to fuel begin() and end(), but this just doesn't feel right.

    Read the article

  • Specify a base classes template parameters while instantiating a derived class?

    - by DaClown
    Hi, I have no idea if the title makes any sense but I can't find the right words to descibe my "problem" in one line. Anyway, here is my problem. There is an interface for a search: template <typename InputType, typename ResultType> class Search { public: virtual void search (InputType) = 0; virtual void getResult(ResultType&) = 0; }; and several derived classes like: template <typename InputType, typename ResultType> class XMLSearch : public Search<InputType, ResultType> { public: void search (InputType) { ... }; void getResult(ResultType&) { ... }; }; The derived classes shall be used in the source code later on. I would like to hold a simple pointer to a Search without specifying the template parameters, then assign a new XMLSearch and thereby define the template parameters of Search and XMLSearch Search *s = new XMLSearch<int, int>(); I found a way that works syntactically like what I'm trying to do, but it seems a bit odd to really use it: template <typename T> class Derived; class Base { public: template <typename T> bool GetValue(T &value) { Derived<T> *castedThis=dynamic_cast<Derived<T>* >(this); if(castedThis) return castedThis->GetValue(value); return false; } virtual void Dummy() {} }; template <typename T> class Derived : public Base { public: Derived<T>() { mValue=17; } bool GetValue(T &value) { value=mValue; return true; } T mValue; }; int main(int argc, char* argv[]) { Base *v=new Derived<int>; int i=0; if(!v->GetValue(i)) std::cout<<"Wrong type int."<<std::endl; float f=0.0; if(!v->GetValue(f)) std::cout<<"Wrong type float."<<std::endl; std::cout<<i<<std::endl<<f; char c; std::cin>>c; return 0; } Is there a better way to accomplish this?

    Read the article

1