SEARCH YOUR SOLUTION HERE  

specialaizing templates --error

, I 'm writitng a simple program which contains the following template template int exch(T& t1 ,T& t2){ T tmp ; tmp = t1; t1 = t2; t2 = tmp; return 1; } When i run this for ...

Posted On: Monday 26th of November 2012 12:15:26 AM Total Views:  358
View Complete with Replies




Related Messages:

What's the best way to do this...? (templates/inheritance problem)   (190 Views)
I've got a big template class "A" and I want to write another template "B" which is exactly the same as A except for one method (let's call it "foo()"). Is there a way to do this without complete copy/paste of "A" I'd like to do it with only one copy of the common code. nb. foo() can't be static, it needs access to class members.... template class A { void foo(); }; template class B { void foo(); // I want a different "foo()" here... }; On a related note, something which came up while I was messing around with this is that when I inherit from a class ("A"), all the constructors in "A" are hidden. class A { public: A(int); }; class B : public A { public: // Compiler writes a constructor for me, hiding A(int)... }; main() { // Doesn't work...compiler says 'int' can't be converted to 'const B&' B b(42); } How can I make A's constructors visible I read the faq and tried adding a "using A::A", but it makes no difference... class B : public A { public: using A::A; // Makes no difference... }; faq: http://www.parashift.com/c++-faq-lit....html#faq-23.9
Newbie question about templates   (109 Views)
It have a simple question about templates. I am using the OpenWatcom compiler. Here is some test code #include using namespace std; int testInt(vector& x1) { return x1[0]; }; template T testTemplate(vector& x1) { T y = ...
Implicit type conversion in combination with templates   (210 Views)
Hi all, please consider the following piece of code: #include template class A { public: A(T t) { prop = t; }; bool operator!=(A a) { return prop != a.prop; } protected: A() { }; T prop; }; ...
"Zero-size" members with templates   (90 Views)
I am trying to create "zero-sized members" of a struct. Knowing that any freestanding object has non-zero size, I am using function typedefs for this purpose, which works quite well as is demonstrated by the following example code. However, ...
variadic templates - packing parameter packs?   (190 Views)
, I'm playing with some C++ <-> interpreted code bindings and so far have found variadic templates to be really helpful in making nice wrappers for the C++ code to call into the interpreted code. However, I haven't yet been ...
templates and their compilation   (104 Views)
hello, this is my first post in a newsgroup, i hope i do everything right first of all, i am sure there have been a lot of "are templates slow" questions around, but i think what i would like to ...
C++ "templates"   (86 Views)
Dear, I have been working with Perl and using templates: http://www.template-toolkit.org/index.html And I am interested to do it in C++. The way that I thought to do it is to generate a grammar to parse(*) the template files and try ...
Problem with templates   (150 Views)
Hi all, I'm having some trouble with templates. I've read up some FAQs, but still cannot seem to find the source of my problem! I have three files: Bezier.h, Bezier.cpp and main.cpp. Here are stripped down versions: --- Bezier.h--- emplate ...
How to simulate variadic templates?   (134 Views)
Hi all, With a current problem, I found the variadic templates in C++0x: http://en.wikipedia.org/wiki/C%2B%2B...adic_templates I would need a template with variable number of parameters, but I need them now! Is there a way to simulate this The background: In an ...
templates declaration and definition   (111 Views)
, I should separate the definition and declaration of template code. This works fine for non-specialized templates. But I do not know how to do this for specialized templates. Example: template class C_B { public: T var; public: C_B( ...
Question about Pointer to Member Typedefs inside templates   (96 Views)
Can anyone please tell me why this code is giving me a C2327 error I am using Visual C++ 2008. template class Foo { }; class Bar { public: int memberOfBar; typedef Foo TypeDefedFooBar; }; ...
help with templates   (181 Views)
, I have a debug header (see source code below), but I'm not sure if it's good style to have four template functions with the same code. Could anyone advice me how to optimize that code Thank you! #ifndef ...
Templates calling other templates?   (126 Views)
I'm designing a protocol stack framework. In my protocol stack framework, I have an arbitrary set of protocol stack layers that pass data between the layers. My framework has a function like "send()" that sends a message from the top ...
Weird behaviour with templates, virtual inheritance and overloadedmethods   (118 Views)
, i discovered a weird behaviour if i use templates together with virtual inheritance and method over. I managed to reproduce my problem with a small example: // *********** ********** template class TypedInterface { public: virtual void ...
templates and friends   (121 Views)
When making a general matrix class I came across the following situation that I don't have an explanation for. For some friend functions I have to declare them in advance while other works anyway. Could anyone care to explain why ...
templates and inheritance   (205 Views)
i have class Impl; //abstract class Impl_A ublic Impl{...};//abstract class Impl_B ublic Impl{...};//abstract class Impl_A_0: public Impl_A{/* implements */}; class S{ public: S(Impl*,...); ...}; class S_A: public S{ public: S_A(Impl_A* impl,...):S(impl){}; class S_B: public S{ public: S_B(Impl_B* impl,...):S(impl){}; //hierarchy ends ...
Are C++ templates a precompiler thing?   (108 Views)
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing I have a feeling the answer I'm going to ...
function templates doesn't support default template parameters?   (110 Views)
Compiling: template T foo(const T& t) {} int main(int argc, char *argv[]) {} gcc complains: ,---- | /Users/william/repo/helloworlds/foo.cpp:2: error: default template | arguments may not be used in function templates `---- But I find in "TC++PL(3rd, ...
virtual base functions, templates, and static functions   (121 Views)
, I searched for an answer to my question and found similar posts, but none that quite addressed the issue I am trying to resolve. Essentially, it seems like I need something like a virtual static function (which I know ...
extensible math functions: variable number of arguments and class templates   (157 Views)
I have a couple of questions about using a variable number of arguments in a function call (...). The context is that I have some mathematical functions I created. I currently pass them a pair of numbers (doubles), and the ...