C++构造函数—构造函数的声明与定义、带参数的构造函数

2020-01-06 12:17:44刘景俊

{
   cout <<"Node constructor is running..." <<endl;
   idata=i;
   cdata=c;
   prior=p;
   next=n;
}
//main.cpp
#include <iostream>
#include "node.h"
using namespace std;
int main()
{
   Node a;//创建一个链表结点对象a,调用构造函数0
   Node b(8);//创建一个链表结点对象b,调用构造函数重载1,参数c默认为'0'
   Node c(8,'F',NULL,NULL);//创建一个链表结点对象c,调用构造函数重载2
   cout <<a.readi() <<' ' <<a.readc() <<endl;
   cout <<b.readi() <<' ' <<b.readc() <<endl;