Sponsored Content
Full Discussion: C++ template error
Top Forums Programming C++ template error Post 302639959 by 915086731 on Sunday 13th of May 2012 09:43:40 PM
Old 05-13-2012
C++ template error

I get some compiling errors about template instantiation Smilie , but I can't find where the syntax errors happens. Can some help me?

Code:
template<typename Type> class SingleList;

template<typename Type> class SingleListNode{
private:
	friend class SingleList<Type>;

	SingleListNode() : next(NULL){}

public:
	friend ostream& operator<< <Type>(ostream& os,SingleListNode<Type>& sln);                  //Error!!!

private:
	SingleListNode *next;
};

template<typename Type> ostream& operator<<(ostream& os,SingleListNode<Type>& out){
	os<<out.data;
	return os;
}

template<typename Type> class SingleList{
public:
	SingleList()
        {
            head =	new SingleListNode<Type> () ;                 //Error!!!
        }
	~SingleList(){
		delete head;
	}

private:
	SingleListNode<Type> *head;
};

Compiler error message:
Code:
|| g++ -g -I ./inc/ -c single_list_test.cpp  -o single_list_test.o
|| single_list.h: In instantiation of ‘SingleListNode<int>’:
single_list.h|25 col 13| instantiated from ‘SingleList<Type>::SingleList() [with Type = int]’
single_list_test.cpp|9 col 18| instantiated from here
single_list.h|10 col 18| error: template-id ‘operator<< <int>’ for ‘std::ostream& operator<<(std::ostream&, SingleListNode<int>&)’ does not match any template declaration
|| make: 
*** [single_list_test.o] Error 1

 

5 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. Programming

Template problem ...

Hi all, Need your help. I am doing a simple template program , getting some error ... here is the code #include <iostream> #include <stdio.h> #include <stdlib.h> #include<iostream> #include<string> #include <sstream> using namespace std; class Base_class { public: Base_class(){... (1 Reply)
Discussion started by: amartya_sock
1 Replies

4. 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

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
std::indirect_array< _Tp >(3)				     Library Functions Manual				     std::indirect_array< _Tp >(3)

NAME
std::indirect_array< _Tp > - SYNOPSIS
Public Types typedef _Tp value_type Public Member Functions indirect_array (const indirect_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 indirect_array & operator= (const indirect_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 gslice_array< _Tp > class valarray< _Tp > Detailed Description template<class _Tp>class std::indirect_array< _Tp > Reference to arbitrary subset of an array. An indirect_array is a reference to the actual elements of an array specified by an ordered array of indices. The way to get an indirect_array is to call operator[](valarray<size_t>) on a valarray. The returned indirect_array then permits carrying operations out on the referenced subset of elements in the original valarray. For example, if an indirect_array is obtained using the array (4,2,0) as an argument, and then assigned to an array containing (1,2,3), then the underlying array will have array[0]==3, array[2]==2, and array[4]==1. Parameters: Tp Element type. Definition at line 84 of file valarray. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Jun 10 2014 std::indirect_array< _Tp >(3)
All times are GMT -4. The time now is 10:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy