2017-12-17 20 views
-4

私のメインのcppファイルにある "Node"の "a = new Node( 'A)"に "予想される型指定子エラー"があります。何も問題が解決していないようにみえプログラムは、ユーザがナビゲートしなければならないことをノードALの迷路を作ることを意図している「期待される型指定子エラー」があるのはなぜですか?

ヘッダーファイル:。。

#pragma once 
#ifndef NODE_H 
#define NODE_H 
#include <string> 

using namespace std; 

namespace mazeGraph 
{ 
    class Node 
    { 
    public: 
     Node(); 
     Node(char newNode); 
     char getName() const; 
     Node *getAdjacentRoom(char direction) const; 
     void edge(char direction, Node *other); 
     string getMovementOptions(); 
    private: 
     char roomName; 
     Node *north, *west, *south, *east; 
    }; 
    typedef Node *nodeptr; 
} 

#endif 

Room.cpp:

#include "stdafx.h" 
#include "Room.h" 
#include <string> 
using namespace std; 

namespace mazeGraph 
{ 
    Node::Node() : roomName(' '), north(NULL), south(NULL), east(NULL), west(NULL) 
    { 
    } 
    Node::Node(char newNode) : roomName(newNode), north(NULL), south(NULL), east(NULL), west(NULL) 
    { 
    } 
    char Node::getName() const 
    { 
     return roomName; 
    } 
    Node* Node::getAdjacentRoom(char direction) const 
    { 
     switch (direction) 
     { 
     case 'N': 
      return north; 
     case 'S': 
      return south; 
     case 'E': 
      return east; 
     case 'W': 
      return west; 
     } 
     return NULL; 
    } 
    void Node::edge(char direction, Node * other) 
    { 
     switch (direction) 
     { 
     case 'N': 
      north = other; 
      break; 
     case 'S': 
      south = other; 
      break; 
     case 'E': 
      east = other; 
      break; 
     case 'W': 
      west = other; 
      break; 
     } 
    } 
    string Node::getMovementOptions() 
    { 
     string movement = ""; 
     if (north != NULL) 
      movement = "N: North "; 
     if (south != NULL) 
      movement = "S: South "; 
     if (east != NULL) 
      movement = "E: East "; 
     if (west != NULL) 
      movement = "W: West "; 
     return movement; 
    } 
} 

メインのcppファイル:

#include "stdafx.h" 
#include <string> 
#include "Room.h" 
#include "Room.cpp" 
#include <iostream> 

using namespace std; 

int main() 
{ 
    mazeGraph::nodeptr a, b, c, d, e, f, g, h, i, j, k, l; 
    a = new Node('A'); 
    b = new Node('B'); 
    c = new Node('C'); 
    d = new Node('D'); 
    e = new Node('E'); 
    f = new Node('F'); 
    g = new Node('G'); 
    h = new Node('H'); 
    i = new Node('I'); 
    j = new Node('J'); 
    k = new Node('K'); 
    l = new Node('L'); 
    return 0; 
} 
+4

質問とは無関係です.1つの.cppファイルを別の.cppファイルに含めることは非常に珍しいことです。だからあなたはおそらくそれをしてはいけません。 –

答えて

2

mazeGraph::Nodeを忘れました。クラスNodeはネームスペースmazeGraphの内部にあるため、コンパイラはネームスペースの外部でそのことを認識しません。

a = new mazeGraph::Node('A'); 
+0

ありがとうございました。そして、他の男のコメントに、私はそこで何をしているのかわかりません。ちょうどそれを削除した。 Ha – Justinodemon619

+0

@ Justinodemon619それがあなたの問題を解決した場合は、答えの左側にあるチェックマークをクリックしてください。 StackOverflowへようこそ:)。 – pepperjack

関連する問題