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:  405
View Complete with Replies

RELATED TOPICS OF C Language PROGRAMMING LANGUAGE




What's the best way to do this...? (templates/inheritance problem)

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
VIEWS ON THIS POST

223

Posted on:

Wednesday 7th November 2012
View Replies!

Newbie question about templates

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 = ...
VIEWS ON THIS POST

138

Posted on:

Saturday 10th November 2012
View Replies!

Implicit type conversion in combination with templates

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; }; ...
VIEWS ON THIS POST

244

Posted on:

Saturday 10th November 2012
View Replies!

"Zero-size" members with templates

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, ...
VIEWS ON THIS POST

113

Posted on:

Saturday 10th November 2012
View Replies!

variadic templates - packing parameter packs?

, 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 ...
VIEWS ON THIS POST

220

Posted on:

Saturday 10th November 2012
View Replies!

templates and their compilation

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 ...
VIEWS ON THIS POST

124

Posted on:

Saturday 10th November 2012
View Replies!

C++ "templates"

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 ...
VIEWS ON THIS POST

101

Posted on:

Saturday 10th November 2012
View Replies!

Problem with templates

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 ...
VIEWS ON THIS POST

185

Posted on:

Saturday 10th November 2012
View Replies!

How to simulate variadic templates?

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 ...
VIEWS ON THIS POST

155

Posted on:

Sunday 11th November 2012
View Replies!

templates declaration and definition

, 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( ...
VIEWS ON THIS POST

131

Posted on:

Sunday 11th November 2012
View Replies!

Question about Pointer to Member Typedefs inside templates

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; }; ...
VIEWS ON THIS POST

117

Posted on:

Sunday 11th November 2012
View Replies!

help with templates

, 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 ...
VIEWS ON THIS POST

217

Posted on:

Sunday 11th November 2012
View Replies!

Templates calling other templates?

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 ...
VIEWS ON THIS POST

147

Posted on:

Sunday 11th November 2012
View Replies!

Weird behaviour with templates, virtual inheritance and overloadedmethods

, 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 ...
VIEWS ON THIS POST

144

Posted on:

Sunday 11th November 2012
View Replies!

templates and friends

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 ...
VIEWS ON THIS POST

139

Posted on:

Sunday 11th November 2012
View Replies!

templates and inheritance

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 ...
VIEWS ON THIS POST

245

Posted on:

Sunday 11th November 2012
View Replies!

Are C++ templates a precompiler thing?

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 ...
VIEWS ON THIS POST

126

Posted on:

Monday 12th November 2012
View Replies!

function templates doesn't support default template parameters?

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, ...
VIEWS ON THIS POST

137

Posted on:

Sunday 25th November 2012
View Replies!

virtual base functions, templates, and static functions

, 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 ...
VIEWS ON THIS POST

140

Posted on:

Sunday 25th November 2012
View Replies!

extensible math functions: variable number of arguments and class templates

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 ...
VIEWS ON THIS POST

174

Posted on:

Monday 26th November 2012
View Replies!