An incomprehensible error occurred when using the class containing the compiled model to compile the template.

Source: Internet
Author: User

Error code:

File 1: Listing list. h

// Configure list. htemplate <typename T> class upload list {public: Upload list ();~ Revoke list (); void clearall (); Private: int * begin; int listcounter;}; # include "counter list. CPP "file 2: Listing list. CPP // configure list. CPP template <typename T> customization list <t> ::~ Counter list () {clearall () ;}template <typename T> counter list <t >:: counter list () {begin = 0; listcounter = 0 ;} template <typename T> void upload list <t >:: clearall (){}

According to the C ++ primer version 4 description of the model containing the compilation (page 1), divide the definition and declaration of the function Template into two files, however, the following error occurs during the compilation test:

Error 1 error c2143: syntax error: Missing ";" (before "<)
E: \ document \ Documents \ Visual Studio 2008 \ projects \ test \ documents list. cpp
5 Test
Error 2 error c4430: The type specifier is missing-it is assumed to be Int. Note: C ++ does not support default int
E: \ document \ Documents \ Visual Studio 2008 \ projects \ test \ documents list. cpp
5 Test
Error 3 error c2988: Unrecognized template declaration/Definition
E: \ document \ Documents \ Visual Studio 2008 \ projects \ test \ documents list. cpp
5 Test
Error 4 error c2059: syntax error: "<"
E: \ document \ Documents \ Visual Studio 2008 \ projects \ test \ documents list. cpp
5 Test
Error 5 Error c2588: ": ~ Invalid list ": Invalid global destructor
E: \ document \ Documents \ Visual Studio 2008 \ projects \ test \ documents list. cpp
5 Test
Error 6 fatal error c1903: failed to recover from previous errors; stopping Compilation
E: \ document \ Documents \ Visual Studio 2008 \ projects \ test \ documents list. cpp
5 Test
Code after correction:

//linkedlistitem.h#ifndef LINKEDLISTITEM_H#define LINKEDLISTITEM_Hnamespace LinkedList{template<class T>class linkedlist;template<class T>class linkedlistitem{friend class linkedlist<T>;protected:T item;linkedlistitem* preview;linkedlistitem* next;public:linkedlistitem();linkedlistitem(const T& itemin,linkedlistitem*p=0,linkedlistitem*n=0);bool operator ==(const linkedlistitem<T>&)const;bool operator <(const linkedlistitem<T>&)const;bool operator >(const linkedlistitem<T>&)const;bool operator <=(const linkedlistitem<T>&)const;bool operator >=(const linkedlistitem<T>&)const;bool operator !=(const linkedlistitem<T>&)const;void changeitem(const T&);void changethis(linkedlistitem*);//void changethis(linkedlistitem&);linkedlistitem*getpreview(){return preview;}linkedlistitem*getnext(){return next;}};}#include "linkedlistitem.cpp"#endif
# Ifndef define listitem_cpp # include <assert. h> # include "listitem. H "namespace shortlist {// template <class T> // class extends listitem; Template <typename T> extends listitem <t >:: extends listitem () {T * TMP = new T (); item = * TMP; Delete TMP; next = 0; Preview = 0;} template <typename T> define listitem <t> :: inclulistitem (const T & itemin, inclulistitem * p = 0, inclulistitem * n = 0): item (itemin), Preview (P), next (n) {}template <typename T> bool extends listitem <t >:: operator <(const extends list: extends listitem <t> & I) const {return item <I. item;} template <typename T> bool publish listitem <t >:: operator <= (const publish list: publish listitem <t> & I) const {return item <= I. item;} template <typename T> bool extends listitem <t >:: operator> (const extends listitem <t> & I) const {return item> I. item;} template <typename T> bool upload listit Em <t>: Operator >=( const implements listitem <t> & I) const {return item> = I. item;} template <typename T> bool publish listitem <t >:: operator ==( const publish listitem <t> & I) const {return item = I. item;} template <typename T> bool extends listitem <t >:: Operator! = (Const upload listitem <t> & I) const {return item! = I. item;} template <typename T> void upload listitem <t >:: changeitem (const T & I) {This-> item = I ;} template <typename T> void inclulistitem <t >:: changethis (inclulistitem <t> * I) {If (this-> Preview) {This-> preview-> next = I; i-> Preview = This-> preview; I-> next = this; this-> Preview = I;} else {// if it is the first this-> Preview = I; i-> Preview = 0; I-> next = This; }}// template <typename T> // void upload listitem <t> :: changethis (custom listitem <t> & I) /// {/// prevent pointing to the memory that has been released in the stack area. // define listitem <t> * TMP = new synchronized listitem <t> (I. item, I. preview, I. next); // changethis (TMP ); /// // assert (TMP -> getnext ()); // assert (getpreview (); // }}# endif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.