templates

How to use static members as template arguments?

I have the following code structure: myClass.h class myClass { public: void DoSomething(void); }; myClass.cpp #include myClass.h static const unsigned length = 5; static myArray<float, length> arrayX; void myClass::DoSomething(void) { // does something using length and array X } Now I want to convert the static variable ...

Template function specialization for specific interface

I have the following piece of code: class ICookable { public: virtual void CookMe () = 0; virtual ~ICookable () {}; }; class Egg : public ICookable { public: virtual void CookMe () {cout << "Egg cooked!" << endl;} }; template <class T> void Cook (T&) { cout << "Item Uncookable!" << endl; } template <> void Cook (ICook...

decltype with a variadic template function

I want to write a simple adder (for giggles) that adds up every argument and returns a sum with appropriate type. Currently, I've got this: #include <iostream> using namespace std; template <class T> T sum(const T& in) { return in; } template <class T, class... P> auto sum(const T& t, const P&... p) -> decltype(t + sum(p...)) { ...

how to implement minheap using template

I need to create a minheap template which includes nodes in it. The problem I have is that I don't know if I need to create a node template class as well, or should it be included inside the heap template class as a struct? ...

How to write a template ?

Hello, i need to write a template with Nodes containing data with 2 data structures : a map and a minimum heap, both got the same nodes in it and every 2 same nodes are connected. the problem is that i need the heap to know the node fields for the heapify for example, and i don't know what's the right way to do so, friends? public fields...

How to overwrite an operator inside a template

hello i am building a template in c++ ,and i need to overwrite the operator "<" inside the template for being able to compare between items inside my data structure. could anyone please tell me how to overwrite it ... should i send a pointer to a function inside the constructor of the template? I got two templates, the first one is Node ...

C++: template params for a class but not a function

Possible Duplicate: Template type deduction in C++ for Class vs Function? When calling a template function, you don't need to specify the template parameters if they are non-ambiguous from your parameters. E.g. for: template<typename T> T foo(T a) { /*...*/ } You can just call foo(1) and it will work, it does not need to be...

C++: error "explicit specialization in non-namespace scope"

template<typename T1, typename T2> class Bimap { public: class Data { private: template<typename T> Data& set(T); template<> Data& set<T1>(typename T1 v) { /*...*/ } }; }; That gives me the error: error: explicit specialization in non-namespace scope 'class Bimap<T1, T2>::Data' I understand what the error ...

how to Override operator <

I'm trying to override operator < as the following : inside Node : bool operator <(const Node* other) { return *(this->GetData()) < *(other->GetData()); } inside vehicle : bool operator <(const Vehicle &other) { return this->GetKilometersLeft() < other.GetKilometersLeft(); } invoking the operator : while (index > 0 && m_he...

Local class template

We can have a local class defined inside a function but this class cannot be a template which is bit annoying and inconsistent. Is there any update on that in C++0x standard? ...

C++: using function pointers as template arguments

I have the following code: template<typename Parent, typename T, void (Parent::*Setter)(T), T (Parent::*Getter)()> struct Property { Parent& obj; Property(Parent& _obj) : obj(_obj) {} Property& operator=(T v) { (obj.*Setter)(v); return *this; } operator T() { return (obj.*Getter)(); } }; template<typename T1, typename T2> class Bim...

XSL, using XML as parameter to template

Is it OK to pass XML to an XSL template through a parameter? For example, below I have the template body call template test1 which passes some XML through the parameter var1. I then attempt to walk to the node a using XPATH <xsl:template name="test1"> <xsl:param name="var1" /> <fo:block> <xsl:value-of select="$var1/a" /...

c++. compile error. am trying to add friend template function with enum template parameter

Hello, dear programmers! Please help with the next code: typedef enum {a1, a2, a3} E; template<E e> int foo() { return static_cast<int>(e); } class A { A() {}; friend int foo<E e>(); }; The compiler says: error C2146: syntax erorr: missing "," before identifier "e" I would be glad if someone could explain my mistake. ...

Templates :Name resolution -->can any one tell an other example for this statement...please

This is the statement from ISO C++ Standard 14.6/8: When looking for the declaration of a name used in a template definition, the usual lookup rules are used for nondependent names. The lookup of names dependent on the template parameters is postponed until the actual template argument is known (14.6.2). Example: #include <iost...

How to define an iterator in a template?

Hello, I'm trying to define an iterator to iterate my map to erase it (destructor) I'm getting an error : incompatible iterator. My destructor looks like this : Consortium<S,T>::~Consortium() { map<const S, Node<T>*>::iterator deleteIterator; for (m_consortiumMap.begin() ; deleteIterator != m_consortiumMap.end() ; del...

Template problem.

Why on earth I can do this: #include <iostream> #include <algorithm> #include <vector> using namespace std; void myfunction (int i) { cout << " " << i; } int main () { vector<int> myvector; myvector.push_back(10); myvector.push_back(20); myvector.push_back(30); cout << "myvector contains:"; for_each (myvector.begin(),...

How to change disabled background color of TextBox in WPF

I've seen the following thread which is related to my question: http://stackoverflow.com/questions/2388833/wpf-combobox-background-color-when-disabled The above deals with changing the Content Template for a ComboBox. I am working with WPF, am somewhat new to Styles and Templates, and I want to change the dull gray background color o...

problems using a class template

i created a template that contains a map. when i try to create an instance of that template i encounter a linking problem with the constructor and destructor. also, when i try to create an instance in main it skips the line while debugging, and doesn't even show it in the locals list. it doesn't compile "DataBase db;" unless i add "()" a...

Normal function not overwriting template function.

Hi, I have to use an external library, but am getting a "multiple definition error" from following template function and its explicit specialization, if it gets called with a std::string. template <typename T> void foo(T& value); template <> void foo(std::string& value); even if I change the 2nd function to void foo(std::string& va...

Django newbie question regarding defining an object with subobjects from models for use in templates

I am somewhat new to Django and have searched for some simple examples of creating objects with subobjects in views so that in templates I can have nested for loops. Here is my models.py for this application... from django.db import models from django import forms class Market(models.Model): name = models.CharField('Market name'...