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
MKDTEMP(3)						     Linux Programmer's Manual							MKDTEMP(3)

NAME
mkdtemp - create a unique temporary directory SYNOPSIS
#include <stdlib.h> char *mkdtemp(char *template); DESCRIPTION
The mkdtemp() function generates a uniquely-named temporary directory from template. The last six characters of template must be XXXXXX and these are replaced with a string that makes the directory name unique. The directory is then created with permissions 0700. Since it will be modified, template must not be a string constant, but should be declared as a character array. RETURN VALUE
The mkdtemp() function returns a pointer to the modified template string on success, and NULL on failure, in which case errno is set appro- priately. ERRORS
EINVAL The last six characters of template were not XXXXXX. Now template is unchanged. Also see mkdir(2) for other possible values for errno. CONFORMING TO
Introduced in OpenBSD 2.2. Available since glibc 2.1.91. SEE ALSO
mkdir(2), mkstemp(3), mktemp(3), tmpnam(3), tempnam(3), tmpfile(3) GNU
2001-10-07 MKDTEMP(3)
All times are GMT -4. The time now is 11:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy