2016-03-31 16 views
-2

このプログラムをデータ構造で作成していますが、node1がこのスコープで宣言されていないという次のエラーが発生します。問題がnode1がこのスコープで宣言されていないC++データ構造

#include<iostream> 

    #include<conio.h> 

    using namespace std; 


      struct node // I have created the struct of node here 

      { 

       int data; 

       struct node *next; 

      }; 

     int main() { 

     node1; 

     node1 *head; 

     head = (node *) malloc(size of (node1)); 

     if(head=null) 

     return; 

     head->data=1; 

     head->next=Null; 

     head->next=(node*)malloc(size of(node1)); 

     head->next->data=2; 

     head->next->next=Null; 

     node1 *current=head; 

      while(current!Null) 

      { 

       cout<<current->data; 

       current=current->next; 
     } 
    } 
+2

あなたは正直なところ、これは有効なC++コードになるはずだったと思いますか? – WhozCraig

+0

はい。これはC++コード –

+0

'#include 'はまだTurbo C++を使用している人ですか? – uSeemSurprised

答えて

1
struct node 
{ 
/* 
*/ 
}; 

node1 head; 

ノードがnode1ではありませんか理解いけません。 また、それはC言語ではなく、C++である

0

node1はどこですか?構造体はというノードです。あなたはどこでもあなたのコードの代わりに、構造体ノードノードを使用したい場合にも、私はあなたがお勧めuseaのtypedefとして:

typedef struct node { //your node data members }node;

関連する問題