C ++,很多错误。也许循环依赖?

时间:2013-05-11 10:26:09

标签: c++

我正在开发一款游戏,它有很多连接在一起的类。工作正常,但现在一切都崩溃了。

1>------ Build started: Project: Razoo, Configuration: Debug Win32 ------
1>  Main.cpp
1>c:\users\ronan\desktop\c++\razoo\razoo\inventory.h(62): warning C4172: returning address of local variable or temporary
1>c:\users\ronan\desktop\c++\razoo\razoo\inventory.h(65): warning C4172: returning address of local variable or temporary
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(21): error C2143: syntax error : missing ';' before '*'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(24): error C2061: syntax error : identifier 'Room'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(76): error C2143: syntax error : missing ';' before '*'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(76): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(77): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(79): warning C4183: 'GetCurrentRoom': missing return type; assumed to be a member function returning 'int'
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(31): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(31): error C2065: 'p_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(32): error C2065: 'p_inventory' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(42): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(78): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(108): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(108): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(113): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(113): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(118): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(118): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(123): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(123): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(156): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(158): error C2065: 'm_currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(158): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(22): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(22): error C2228: left of '.length' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(27): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(72): error C2227: left of '->GetDesc' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(84): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(88): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(88): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(91): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(95): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(95): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(98): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(102): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(102): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(105): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(109): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(109): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(115): error C2227: left of '->GetInventory' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(115): error C2228: left of '.Size' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(116): error C2227: left of '->GetInventory' must point to class/struct/union/generic type
1>          type is 'int *'
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(116): error C2228: left of '.GetItemNames' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\generalutils.h(154): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(128): error C2143: syntax error : missing ';' before '&'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(128): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(128): error C2061: syntax error : identifier 'HashTable'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(129): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(214): warning C4183: 'InitializeRooms': missing return type; assumed to be a member function returning 'int'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(216): error C2061: syntax error : identifier 'HashTable'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(130): error C2065: 'p_filename' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(155): error C2065: 'Room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(155): error C2065: 'temp' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C2065: 'Room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C2146: syntax error : missing ';' before identifier 'room'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C2065: 'temp' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(183): error C3861: 'room': identifier not found
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2228: left of '.Insert' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2065: 'room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(185): error C2228: left of '.GetName' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2228: left of '.Find' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(202): error C2228: left of '.SetNorth' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2228: left of '.Find' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(204): error C2228: left of '.SetSouth' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2228: left of '.Find' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(206): error C2228: left of '.SetEast' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2228: left of '.Find' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(208): error C2228: left of '.SetWest' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2146: syntax error : missing ';' before identifier 'level'
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2065: 'p_roomtable' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2228: left of '.Find' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(212): error C3861: 'level': identifier not found
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(213): error C2065: 'level' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(218): error C2065: 'p_filename' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(231): error C2065: 'Room' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(231): error C2065: 'currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2065: 'currentRoom' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2065: 'p_rooms' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2228: left of '.Find' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(253): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(263): error C2065: 'p_numItems' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(265): error C2065: 'p_items' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(265): error C2228: left of '.GetName' must have class/struct/union
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(267): error C2065: 'p_items' : undeclared identifier
1>c:\users\ronan\desktop\c++\razoo\razoo\initializer.h(272): error C2065: 'currentRoom' : undeclared identifier
1>d:\programs\microsoft visual studio 11.0\vc\include\regex(1670): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我虽然在某个地方有一个不匹配的支架,或者一个缺失;在课程结束时,但我确实检查了代码中的每一个,所以我认为我已经排除了这一点。

从第一个错误开始:

1>c:\users\ronan\desktop\c++\razoo\razoo\player.h(21): error C2143: syntax error : missing ';' before '*'

以及它指向的代码:

    #ifndef PLAYER_H
#define PLAYER_H

#include <string>
#include <fstream>

#include "Room.h"
#include "Inventory.h"
#include "Array.h"


class Player
{
private:
    string m_name;
    int m_health;
    int m_confidence;
    int m_humor;
    int m_speed;
    Room* m_currentRoom; //Line 21
    Inventory m_inventory;

我认为#include "Room.h"无法正常工作? 我是否混淆了某种循环依赖(我现在甚至都不完全理解它们)? 或者还有其他一些“常见”问题可以同时调用所有这些错误吗? 这里的第一篇文章,所以不确定你是否需要更多代码或任何东西(或者如果我搞砸了任何合成器!)
谢谢!

1 个答案:

答案 0 :(得分:0)

您可以通过从“Player.h”中删除#include "Room.h"并用以下内容替换该行来解决循环依赖关系:

class Room;

这样可以正常工作,因为看起来你只使用指向Room类的指针。 在Player.cpp中,如果你需要Room的方法和成员,或者你曾经取消引用指针,你可以在顶部执行此操作:

#include "Player.h"
#include "Room.h"

如果这不起作用,您可以发布更多代码吗?