-
March 21st, 2007, 02:23 PM
#1
error: see reference to class template instantiation 'List<NODETYPE>' being compiled
I am trying to modify an address book program to use a link list and I am having problems
error: see reference to class template instantiation 'List<NODETYPE>' being compiled
I am getting this error in this file:
addressBookType.h
from this line:
List<extPersonType> theList;
Code:
//addressBookType.h
#ifndef H_addressBookType
#define H_addressBookType
#include <string>
#include <fstream>
#include "extPersonType.h"
#include "list.h"
using namespace std;
class addressBookType
{
public:
void print() const;
void printNameInTheMonth(int month);
void printInfoOf(string lName);
void printNamesWithStatus(string status);
void printAt(int i);
void printNamesBetweenLastNames(string last1, string last2);
void insertAt(const extPersonType& eP, int i);
void insertLast(const extPersonType& eP);
int search(string lName);
void sort();
void saveData(ofstream&);
addressBookType();
private:
extPersonType list[500];
List<extPersonType> theList;
int length;
};
#endif
listnode.h
Code:
// Fig. 15.3: listnode.h
// Template ListNode class definition.
#ifndef LISTNODE_H
#define LISTNODE_H
// forward declaration of class List
template< class NODETYPE > class List;
template< class NODETYPE >
class ListNode {
friend class List< NODETYPE >; // make List a friend
public:
ListNode( const NODETYPE & ); // constructor
NODETYPE getData() const; // return data in node
private:
NODETYPE data; // data
ListNode< NODETYPE > *nextPtr; // next node in list
}; // end class ListNode
// constructor
template< class NODETYPE >
ListNode< NODETYPE >::ListNode( const NODETYPE &info )
: data( info ),
nextPtr( 0 )
{
// empty body
} // end ListNode constructor
// return copy of data in node
template< class NODETYPE >
NODETYPE ListNode< NODETYPE >::getData() const
{
return data;
} // end function getData
#endif
list.h
Code:
// Fig. 15.4: list.h
// Template List class definition.
#ifndef LIST_H
#define LIST_H
#include <iostream>
using std::cout;
#include <new>
#include "listnode.h" // ListNode class definition
template< class NODETYPE >
class List {
public:
List(); // constructor
~List(); // destructor
void insertAtFront( const NODETYPE & );
void insertAtBack( const NODETYPE & );
bool removeFromFront( NODETYPE & );
bool removeFromBack( NODETYPE & );
bool isEmpty() const;
void print() const;
private:
ListNode< NODETYPE > *firstPtr; // pointer to first node
ListNode< NODETYPE > *lastPtr; // pointer to last node
// utility function to allocate new node
ListNode< NODETYPE > *getNewNode( const NODETYPE & );
}; // end class List
// default constructor
template< class NODETYPE >
List< NODETYPE >::List()
: firstPtr( 0 ),
lastPtr( 0 )
{
// empty body
} // end List constructor
// destructor
template< class NODETYPE >
List< NODETYPE >::~List()
{
if ( !isEmpty() ) { // List is not empty
cout << "Destroying nodes ...\n";
ListNode< NODETYPE > *currentPtr = firstPtr;
ListNode< NODETYPE > *tempPtr;
while ( currentPtr != 0 ) { // delete remaining nodes
tempPtr = currentPtr;
cout << tempPtr->data << '\n';
currentPtr = currentPtr->nextPtr;
delete tempPtr;
} // end while
} // end if
cout << "All nodes destroyed\n\n";
} // end ~List destructor
// insert node at front of list
template< class NODETYPE >
void List< NODETYPE >::insertAtFront( const NODETYPE &value )
{
ListNode< NODETYPE > *newPtr = getNewNode( value );
if ( isEmpty() ) // List is empty
firstPtr = lastPtr = newPtr;
else { // List is not empty
newPtr->nextPtr = firstPtr;
firstPtr = newPtr;
} // end else
} // end function insertAtFront
// insert node at back of list
template< class NODETYPE >
void List< NODETYPE >::insertAtBack( const NODETYPE &value )
{
ListNode< NODETYPE > *newPtr = getNewNode( value );
if ( isEmpty() ) // List is empty
firstPtr = lastPtr = newPtr;
else { // List is not empty
lastPtr->nextPtr = newPtr;
lastPtr = newPtr;
} // end else
} // end function insertAtBack
// delete node from front of list
template< class NODETYPE >
bool List< NODETYPE >::removeFromFront( NODETYPE &value )
{
if ( isEmpty() ) // List is empty
return false; // delete unsuccessful
else {
ListNode< NODETYPE > *tempPtr = firstPtr;
if ( firstPtr == lastPtr )
firstPtr = lastPtr = 0;
else
firstPtr = firstPtr->nextPtr;
value = tempPtr->data; // data being removed
delete tempPtr;
return true; // delete successful
} // end else
} // end function deleteFromFront
// delete node from back of list
template< class NODETYPE >
bool List< NODETYPE >::removeFromBack( NODETYPE &value )
{
if ( isEmpty() )
return false; // delete unsuccessful
else {
ListNode< NODETYPE > *tempPtr = lastPtr;
if ( firstPtr == lastPtr )
firstPtr = lastPtr = 0;
else {
ListNode< NODETYPE > *currentPtr = firstPtr;
// locate second-to-last element
while ( currentPtr->nextPtr != lastPtr )
currentPtr = currentPtr->nextPtr;
lastPtr = currentPtr;
currentPtr->nextPtr = 0;
} // end else
value = tempPtr->data;
delete tempPtr;
return true; // delete successful
} // end else
} // end function deleteFromBack
// is List empty?
template< class NODETYPE >
bool List< NODETYPE >::isEmpty() const
{
return firstPtr == 0;
} // end function isEmpty
// return pointer to newly allocated node
template< class NODETYPE >
ListNode< NODETYPE > *List< NODETYPE >::getNewNode(
const NODETYPE &value )
{
return new ListNode< NODETYPE >( value );
} // end function getNewNode
// display contents of List
template< class NODETYPE >
void List< NODETYPE >::print() const
{
if ( isEmpty() ) {
cout << "The list is empty\n\n";
return;
} // end if
ListNode< NODETYPE > *currentPtr = firstPtr;
cout << "The list is: ";
while ( currentPtr != 0 ) {
cout << currentPtr->data << ' ';
currentPtr = currentPtr->nextPtr;
} // end while
cout << "\n\n";
} // end function print
#endif
thanks
-
March 21st, 2007, 02:36 PM
#2
Re: error: see reference to class template instantiation 'List<NODETYPE>' being compiled
What is the full error message? It could be that extPersonType is not default-constructable, not copyable or something like that.
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
March 21st, 2007, 02:54 PM
#3
Re: error: see reference to class template instantiation 'List<NODETYPE>' being compiled
Originally Posted by Yves M
What is the full error message? It could be that extPersonType is not default-constructable, not copyable or something like that.
I got errors trying to post all of it, so I had to cut some of it out
list.h(57) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'extPersonType' (or there is no acceptable conversion)
c:\program files\microsoft visual studio 8\vc\include\ostream(650): could be 'std::basic_ostream<_Elem,_Traits> &std:perator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(697): or 'std::basic_ostream<_Elem,_Traits> &std:perator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
]
while trying to match the argument list '(std:stream, extPersonType)'
m:\c++ data structures\c++datastructures_assignment2\c++datastructures_assignment2\list.h(48) : while compiling class template member function 'List<NODETYPE>::~List(void)'
with
[
NODETYPE=extPersonType
]
m:\c++ data structures\c++datastructures_assignment2\c++datastructures_assignment2\addressbooktype.h(39) : see reference to class template instantiation 'List<NODETYPE>' being compiled
with
[
NODETYPE=extPersonType
]
addressTypeImp.cpp
Ch12_Ex6_mainProgram.cpp
dataTypeImp.cpp
extPersonTypeImp.cpp
personTypeImp.cpp
test.cpp
Generating Code...
Build log was saved at "file://m:\C++ Data Structures\C++DataStructures_Assignment2\C++DataStructures_Assignment2\Debug\BuildLog.htm"
C++DataStructures_Assignment2 - 1 error(s), 0 warning(s)
-
March 21st, 2007, 04:22 PM
#4
Re: error: see reference to class template instantiation 'List<NODETYPE>' being compiled
Provide an overload for the streaming operator for your 'extPersonType' class.
Code:
class extPersonType
{
public:
friend ostream& operator<< (ostream& out, const extPersonType &obj);
...
};
Viggy
-
March 21st, 2007, 06:21 PM
#5
Re: error: see reference to class template instantiation 'List<NODETYPE>' being compiled
Originally Posted by Mr. Mojo Risin
I got errors trying to post all of it, so I had to cut some of it out
list.h(57) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'extPersonType' (or there is no acceptable conversion)
c:\program files\microsoft visual studio 8\vc\include\ostream(650): could be 'std::basic_ostream<_Elem,_Traits> &std: perator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(697): or 'std::basic_ostream<_Elem,_Traits> &std: perator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
]
while trying to match the argument list '(std: stream, extPersonType)'
m:\c++ data structures\c++datastructures_assignment2\c++datastructures_assignment2\list.h(48) : while compiling class template member function 'List<NODETYPE>::~List(void)'
with
[
NODETYPE=extPersonType
]
m:\c++ data structures\c++datastructures_assignment2\c++datastructures_assignment2\addressbooktype.h(39) : see reference to class template instantiation 'List<NODETYPE>' being compiled
with
[
NODETYPE=extPersonType
]
addressTypeImp.cpp
Ch12_Ex6_mainProgram.cpp
dataTypeImp.cpp
extPersonTypeImp.cpp
personTypeImp.cpp
test.cpp
Generating Code...
Build log was saved at "file://m:\C++ Data Structures\C++DataStructures_Assignment2\C++DataStructures_Assignment2\Debug\BuildLog.htm"
C++DataStructures_Assignment2 - 1 error(s), 0 warning(s)
thank you
-
March 21st, 2007, 10:48 PM
#6
Re: error: see reference to class template instantiation 'List<NODETYPE>' being compiled
somewhat related to this problem (I'm actually working on the same thing) I keep getting a problem with a double linked list node: Here's the node:
Code:
template <class Type>
struct nodeType
{
Type info;
nodeType<Type> *next;
nodeType<Type> *back;
};
Here's the class that I'm using:
Code:
class addressBookType : public doublyLinkedList<extPersonType>
{
public:
void searchAddBook(string name) const;
void printAddBook();
void reversePrintAddBook();
void printBirthDay(int month);
void printRange(string name1, string name2);
void printRelation(string relate);
void addEntry(string fname, string lname, int month, int day, int year, string add, string cit, string sta, string z, string relate = "", string pnum = "");
void deleteEntry(string fullname);
};
and here's the function that's giving me the error:
Code:
void addressBookType::addEntry(string fname, string lname, int month, int day, int year, string add, string cit, string sta, string z, string relate, string pnum)
{
nodeType<extPersonType> *current;
nodeType<extPersonType> *trailCurrent;
nodeType<extPersonType> *newNode;
bool found;
newNode = new nodeType<extPersonType>; // error is on this line
newNode->info.setExtPersonType(fname, lname, month, day, year, add, cit, sta, z, relate, pnum);
newNode->next = NULL;
newNode->back = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
count++;
}
else
{
found = false;
current = first;
while (current != NULL && !found)
{
if (current->info.getLastName() >= lname)
found = true;
else
{
trailCurrent = current;
current = current->next;
}
if (current == first)
{
first->back = newNode;
newNode->next = first;
first = newNode;
count++;
}
else
{
if (current != NULL)
{
trailCurrent->next = newNode;
newNode->back = trailCurrent;
newNode->next = current;
current->back = newNode;
}
else
{
trailCurrent->next = newNode;
newNode->back = trailCurrent;
last = newNode;
}
count++;
}
}
}
}
The error is:
Error 1 error C2512: 'nodeType<Type>' : no appropriate default constructor available
Last edited by Damon_Dusk; March 21st, 2007 at 10:56 PM.
-
March 22nd, 2007, 02:28 AM
#7
Re: error: see reference to class template instantiation 'List<NODETYPE>' being compiled
Make sure that extPersonType has a default constructor. This is a constructor without any parameters or with defaults for all parameters.
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|