亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3590 | 回復: 5
打印 上一主題 下一主題

[C++] 麻煩大神指出錯誤 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-03-19 22:38 |只看該作者 |倒序瀏覽
本帖最后由 nOneee_ 于 2014-03-19 23:47 編輯

template<class T>
class Link{//鏈表結點定義
        public:
                T data;
                Link<T>*next;

                Link(const T x,const Link<T>*nextValue=NULL){
                        data=x;
                        next=nextValue;
                }

                Link(const Link<T>*nextValue){
                        next=nextValue;
                }
                       
};


template<class T>
class InkList:public Link<T>{//定義鏈表類型
        private:
                Link<T>*head,*tail;
        public:
                InkList();//構造
                ~InkList();//析構
            int input(const T x);//輸入  
                int invert();
            void output();//輸出
};

template<class T>//構造
InkList<T>::InkList( ){
        head=tail=new Link<T>;
}
template<class T>//析構
InkList<T>::~InkList(){
        Link<T>*tmp;
        while(head!=NULL)
        {
                tmp=head;
                head=head->next;
                delete tmp;
        }
}

template<class T>//輸入
int InkList<T>::input(const T x)
{
               
        Link<T>*q;   
        q=new Link<T>;
        q->data=x;
        if(!q)
                return 0;
        q->next=NULL;
        tail->next=q;
        tail=q;
        return 1;
}

template<class T>
int InkList<T>::invert()
{
         Link<T>*p,*q;
         p=head->next;                 
         head->next=NULL;      
while(p!=NULL)
{
        r=p->next;               
    p->next=head->next;
    head->next=p;      
    p=r;                 
    }
}

template<class T>//輸出
void InkList<T>:utput()
{
        Link<T>*q;
        q=head->next;
        while(q!=NULL)
        {
                cout<<q->data;
                q=q->next;
        }
        cout<<endl;
}
===========================================
#include<iostream>
#include"8.h"
using namespace std;



void main()
{
        InkList<int>list;
        int x;
        cout<<"請輸入需逆置的鏈表"<<endl;
        cin>>x;
                list.input(x);
                list.invert();
                list.output();
               
}
===========================================
j:\數(shù)據(jù)結構\ex2\8.h(32) : error C2512: 'Link<int>' : no appropriate default constructor available
        c:\program files (x86)\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function '__thiscall InkList<int>::InkList<int>(void)'
j:\數(shù)據(jù)結構\ex2\8.h(33) : error C2512: 'Link<int>' : no appropriate default constructor available
        c:\program files (x86)\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function '__thiscall InkList<int>::InkList<int>(void)'
j:\數(shù)據(jù)結構\ex2\8.h(51) : error C2512: 'Link<int>' : no appropriate default constructor available
        c:\program files (x86)\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function 'int __thiscall InkList<int>::input(const int)'

論壇徽章:
0
2 [報告]
發(fā)表于 2014-03-19 23:48 |只看該作者
自頂一個,麻煩大神指點.

論壇徽章:
6
技術圖書徽章
日期:2013-11-13 11:11:27子鼠
日期:2014-02-20 17:54:13處女座
日期:2014-06-16 17:43:33午馬
日期:2014-08-08 09:11:17未羊
日期:2014-08-10 11:57:072015年辭舊歲徽章
日期:2015-03-03 16:54:15
3 [報告]
發(fā)表于 2014-03-20 09:08 |只看該作者
no appropriate default constructor available

這里寫得很明確了。

論壇徽章:
9
摩羯座
日期:2013-08-15 15:18:48獅子座
日期:2013-09-12 18:07:47金牛座
日期:2013-09-16 13:23:09辰龍
日期:2013-10-09 09:03:27白羊座
日期:2013-10-17 13:32:44子鼠
日期:2014-04-23 15:09:38戌狗
日期:2014-09-17 11:37:542015年亞洲杯之韓國
日期:2015-03-26 10:16:442015亞冠之武里南聯(lián)
日期:2015-08-18 14:55:52
4 [報告]
發(fā)表于 2014-03-20 14:45 |只看該作者
先不說邏輯是否正確,語法上的錯誤提示已經(jīng)很明確。
Link類里面定義了兩個帶參數(shù)的構造函數(shù),根據(jù)語法一旦定義了構造函數(shù),那么默認的不帶參數(shù)的構造函數(shù)就不會自動生成了;而InkList從Link繼承,其構造函數(shù)InkList<T>::InkList沒有在初始化列表中顯式調(diào)用父類Link的構造函數(shù),那么默認會調(diào)用不帶參數(shù)版本的Link構造函數(shù),但是Link沒有這樣的構造函數(shù),于是編譯錯誤。
從語法角度解決這個問題,有幾種選擇,一是定義一個Link的不帶參數(shù)的構造函數(shù),里面啥都不干就行了,二是InkList構造里面顯式調(diào)用父類的其中一個構造函數(shù)也可以。

論壇徽章:
1
戌狗
日期:2014-03-04 13:31:12
5 [報告]
發(fā)表于 2014-03-20 15:54 |只看該作者
設計都有問題吧。InkList為什么要繼承Link?InkList明顯不是一個Link.

論壇徽章:
0
6 [報告]
發(fā)表于 2014-03-20 23:48 |只看該作者
回復 4# w_anthony

2,的意思是在   inklist括號里面加& Link(const T x,const Link<T>*nextValue=NULL)和&Link(const Link<T>*nextValue)的意思嗎?
   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP