Sponsored Content
Full Discussion: Template problem ...
Top Forums Programming Template problem ... Post 302239595 by spirtle on Wednesday 24th of September 2008 04:52:56 AM
Old 09-24-2008
You didn't post the code that doesn't work, but I guess that you want to define the method template in a separate file rather than in the definition of the class, as one often does for normal class methods.
Short answer; you can't.

There is, no doubt, a better explanation in a text book somewhere, but here goes...
Templates are not like normal code; you cannot define them where ever you like. When the compiler sees your call to
Code:
int a;
Base_class::fun(a,check);

here is no method with signature
Code:
fun(int, string&);

so it has to create one from the template you supplied. This means that the compiler has to be able to see the both the template (so it knows how to build the function) and the call (so it knows what types to build the function with) at the same time. So the template and the code calling the method must be in the same compilation unit.
You don't have to have the method template defined inline, but you must have it defined where the class is defined.
 

6 More Discussions You Might Find Interesting

1. Programming

About template constraints

Hi, i have class template, 1)can i override the copy constructor 2)can we have virtual function in class template if not plz tel why? I tried , compile error comes for me... Thanks Sarwan (0 Replies)
Discussion started by: sarwan
0 Replies

2. UNIX for Dummies Questions & Answers

vi calling template

Hello. I want to copy temp files when I make a new file by vi. For example, 09:32:52 ~/ $ mkdir test 09:33:03 ~/ $ cd test/ 09:33:09 ~/test/ $ ls 09:33:16 ~/test/ $ vi test.cpp 09:34:37 ~/test/ $ cat test.cpp #include <iostream> int main() { } 09:34:48 ~/test/ $ vi test.bash 09:35:19... (1 Reply)
Discussion started by: Euler04
1 Replies

3. Shell Programming and Scripting

Help with template like solution

hi experts, i'm trying to do this: file1 is a template. might have kinds of 'funny' characters. sample: <body> <form> <p><input type="text" name="abc"/></p> &nbsp; <p><my_content></p> </form> </body> file2 is a file that contains lots of text. this might be very big. might have... (2 Replies)
Discussion started by: xjohnu
2 Replies

4. Programming

C++ template error

I get some compiling errors about template instantiation :wall: , but I can't find where the syntax errors happens. Can some help me? template<typename Type> class SingleList; template<typename Type> class SingleListNode{ private: friend class SingleList<Type>; SingleListNode() :... (1 Reply)
Discussion started by: 915086731
1 Replies

5. Programming

Calling template at once

Hello Again, I am just wanted to know if we can call the Template using "require_once" at PHP? Any views around happy to discuss. Thanks in Advance (2 Replies)
Discussion started by: AimyThomas
2 Replies

6. UNIX for Dummies Questions & Answers

Cacti SNMP Generic OID template, NaN problem

Hello All, I have installed cacti and I have Nan values on created graph. I really appreciate any help. I have done the following: 1. Linux Ubuntu 12.04.2 LTS 64 bits 2. apt-get install cacti // the cacti Version 0.8.7i was installed 3. Accessed "http://MyIP/cacti/index.php" 4. Set SNMP... (0 Replies)
Discussion started by: AndreiM
0 Replies
std::slice_array< _Tp >(3)				     Library Functions Manual					std::slice_array< _Tp >(3)

NAME
std::slice_array< _Tp > - SYNOPSIS
Public Types typedef _Tp value_type Public Member Functions slice_array (const slice_array &) void operator%= (const valarray< _Tp > &) const template<class _Dom > void operator%= (const _Expr< _Dom, _Tp > &) const void operator&= (const valarray< _Tp > &) const template<class _Dom > void operator&= (const _Expr< _Dom, _Tp > &) const void operator*= (const valarray< _Tp > &) const template<class _Dom > void operator*= (const _Expr< _Dom, _Tp > &) const void operator+= (const valarray< _Tp > &) const template<class _Dom > void operator+= (const _Expr< _Dom, _Tp > &) const void operator-= (const valarray< _Tp > &) const template<class _Dom > void operator-= (const _Expr< _Dom, _Tp > &) const void operator/= (const valarray< _Tp > &) const template<class _Dom > void operator/= (const _Expr< _Dom, _Tp > &) const void operator<<= (const valarray< _Tp > &) const template<class _Dom > void operator<<= (const _Expr< _Dom, _Tp > &) const slice_array & operator= (const slice_array &) void operator= (const valarray< _Tp > &) const void operator= (const _Tp &) const template<class _Dom > void operator= (const _Expr< _Dom, _Tp > &) const void operator>>= (const valarray< _Tp > &) const template<class _Dom > void operator>>= (const _Expr< _Dom, _Tp > &) const void operator^= (const valarray< _Tp > &) const template<class _Dom > void operator^= (const _Expr< _Dom, _Tp > &) const void operator|= (const valarray< _Tp > &) const template<class _Dom > void operator|= (const _Expr< _Dom, _Tp > &) const Friends class valarray< _Tp > Detailed Description template<class _Tp>class std::slice_array< _Tp > Reference to one-dimensional subset of an array. A slice_array is a reference to the actual elements of an array specified by a slice. The way to get a slice_array is to call operator[](slice) on a valarray. The returned slice_array then permits carrying operations out on the referenced subset of elements in the original valarray. For example, operator+=(valarray) will add values to the subset of elements in the underlying valarray this slice_array refers to. Parameters: Tp Element type. Definition at line 80 of file valarray. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Jun 10 2014 std::slice_array< _Tp >(3)
All times are GMT -4. The time now is 11:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy