风中追风的少年 发表于 2014-12-24 14:50:08

栈的指针问题

#include<iostream>
using namespace std;
typedef struct {
        int data;
        struct node *next;
}Lnode,*pList;//第二个是指向结点结构的指针。
class list{
public:
          list();//构造函数
          int length();//求链表长度。
          ~list();//析构函数。
private:
          Lnode *head;    //头结点。
};
//定义构造函数.
list::list(){
        Lnode *head=new Lnode;
        head->next=NULL;       //将头结点下一个地址指向空。   
}
//定义求表长函数.
int list::length(){
       Lnode*p=head->next;
       int n=0;
       if(p=NULL){
               cout<<"表为空"<<endl;
             return 0;
       }
       else {

             while(p!=NULL){
                     p=p->next;
                     n++;
                   }
                   return n;
       }
}

int main(){
        list L;
        L.length();
        L.~list;
   return 0;
}

风中追风的少年 发表于 2014-12-24 14:59:20

VC6.0报错error C2440: 'initializing' : cannot convert from 'struct node *' to 'Lnode *'
      Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast,求解释

zjc78361 发表于 2015-1-21 20:19:55

不懂
页: [1]
查看完整版本: 栈的指针问题