c++,很多错误.也许是循环依赖
C++ , Lots of Errors. Maybe Circular Dependency?
我正在制作一款游戏,它有一堆类链接在一起。本来很好,但现在一团糟。
1>------ Build started: Project: Razoo, Configuration: Debug Win32 ------
1> Main.cpp
1>c:usersronandesktopc++razoorazooinventory.h(62): warning C4172: returning address of local variable or temporary
1>c:usersronandesktopc++razoorazooinventory.h(65): warning C4172: returning address of local variable or temporary
1>c:usersronandesktopc++razoorazooplayer.h(21): error C2143: syntax error : missing ';' before '*'
1>c:usersronandesktopc++razoorazooplayer.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersronandesktopc++razoorazooplayer.h(24): error C2061: syntax error : identifier 'Room'
1>c:usersronandesktopc++razoorazooplayer.h(76): error C2143: syntax error : missing ';' before '*'
1>c:usersronandesktopc++razoorazooplayer.h(76): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersronandesktopc++razoorazooplayer.h(77): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersronandesktopc++razoorazooplayer.h(79): warning C4183: 'GetCurrentRoom': missing return type; assumed to be a member function returning 'int'
1>c:usersronandesktopc++razoorazooplayer.h(31): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(31): error C2065: 'p_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(32): error C2065: 'p_inventory' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(42): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(78): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(108): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(108): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooplayer.h(113): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(113): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooplayer.h(118): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(118): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooplayer.h(123): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(123): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooplayer.h(156): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(158): error C2065: 'm_currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooplayer.h(158): error C2227: left of '->GetName' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazoogeneralutils.h(22): error C2227: left of '->GetName' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(22): error C2228: left of '.length' must have class/struct/union
1>c:usersronandesktopc++razoorazoogeneralutils.h(27): error C2227: left of '->GetName' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(72): error C2227: left of '->GetDesc' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(84): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(88): error C2227: left of '->GetNorth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(88): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazoogeneralutils.h(91): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(95): error C2227: left of '->GetSouth' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(95): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazoogeneralutils.h(98): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(102): error C2227: left of '->GetEast' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(102): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazoogeneralutils.h(105): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(109): error C2227: left of '->GetWest' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(109): error C2227: left of '->GetName' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazoogeneralutils.h(115): error C2227: left of '->GetInventory' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(115): error C2228: left of '.Size' must have class/struct/union
1>c:usersronandesktopc++razoorazoogeneralutils.h(116): error C2227: left of '->GetInventory' must point to class/struct/union/generic type
1> type is 'int *'
1>c:usersronandesktopc++razoorazoogeneralutils.h(116): error C2228: left of '.GetItemNames' must have class/struct/union
1>c:usersronandesktopc++razoorazoogeneralutils.h(154): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:usersronandesktopc++razoorazooinitializer.h(128): error C2143: syntax error : missing ';' before '&'
1>c:usersronandesktopc++razoorazooinitializer.h(128): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersronandesktopc++razoorazooinitializer.h(128): error C2061: syntax error : identifier 'HashTable'
1>c:usersronandesktopc++razoorazooinitializer.h(129): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersronandesktopc++razoorazooinitializer.h(214): warning C4183: 'InitializeRooms': missing return type; assumed to be a member function returning 'int'
1>c:usersronandesktopc++razoorazooinitializer.h(216): error C2061: syntax error : identifier 'HashTable'
1>c:usersronandesktopc++razoorazooinitializer.h(130): error C2065: 'p_filename' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(155): error C2065: 'Room' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(155): error C2065: 'temp' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(183): error C2065: 'Room' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(183): error C2146: syntax error : missing ';' before identifier 'room'
1>c:usersronandesktopc++razoorazooinitializer.h(183): error C2065: 'temp' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(183): error C3861: 'room': identifier not found
1>c:usersronandesktopc++razoorazooinitializer.h(185): error C2065: 'p_roomtable' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(185): error C2228: left of '.Insert' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(185): error C2065: 'room' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(185): error C2228: left of '.GetName' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(202): error C2065: 'p_roomtable' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(202): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(202): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazooinitializer.h(202): error C2228: left of '.SetNorth' must have class/struct/union
1>c:usersronandesktopc++razoorazooinitializer.h(204): error C2065: 'p_roomtable' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(204): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(204): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazooinitializer.h(204): error C2228: left of '.SetSouth' must have class/struct/union
1>c:usersronandesktopc++razoorazooinitializer.h(206): error C2065: 'p_roomtable' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(206): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(206): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazooinitializer.h(206): error C2228: left of '.SetEast' must have class/struct/union
1>c:usersronandesktopc++razoorazooinitializer.h(208): error C2065: 'p_roomtable' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(208): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(208): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazooinitializer.h(208): error C2228: left of '.SetWest' must have class/struct/union
1>c:usersronandesktopc++razoorazooinitializer.h(212): error C2146: syntax error : missing ';' before identifier 'level'
1>c:usersronandesktopc++razoorazooinitializer.h(212): error C2065: 'p_roomtable' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(212): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(212): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazooinitializer.h(212): error C3861: 'level': identifier not found
1>c:usersronandesktopc++razoorazooinitializer.h(213): error C2065: 'level' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(218): error C2065: 'p_filename' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(231): error C2065: 'Room' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(231): error C2065: 'currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(253): error C2065: 'currentRoom' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(253): error C2065: 'p_rooms' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(253): error C2228: left of '.Find' must have class/struct/union
1> type is ''unknown-type''
1>c:usersronandesktopc++razoorazooinitializer.h(253): error C2227: left of '->m_data' must point to class/struct/union/generic type
1>c:usersronandesktopc++razoorazooinitializer.h(263): error C2065: 'p_numItems' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(265): error C2065: 'p_items' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(265): error C2228: left of '.GetName' must have class/struct/union
1>c:usersronandesktopc++razoorazooinitializer.h(267): error C2065: 'p_items' : undeclared identifier
1>c:usersronandesktopc++razoorazooinitializer.h(272): error C2065: 'currentRoom' : undeclared identifier
1>d:programsmicrosoft visual studio 11.0vcincluderegex(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:usersronandesktopc++razoorazooplayer.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"
不能正常工作?
我是否混淆了某种循环依赖关系(我现在甚至不完全理解它们)?
或者是否有其他一些"常见"问题会同时引发所有这些错误?
在这里的第一个帖子,所以不确定你是否需要一些更多的代码或任何东西(或者如果我搞砸了任何语法!)
谢谢!
您可以通过从"Player.h"中删除#include "Room.h"
并将该行替换为以下内容来解决循环依赖:
class Room;
这将工作得很好,因为它看起来你只使用一个指向Room类的指针。在player。cpp中,如果你需要Room的方法和成员或者你需要解引用指针,你可以在顶部这样做:
#include "Player.h"
#include "Room.h"
如果这不起作用,你能发布更多的代码吗?
相关文章:
- C++GTKMM gui循环依赖关系
- 如何在头文件中声明类模板(由于循环依赖关系)
- 如何在具有循环依赖的类中dynamic_cast?
- C++模板方法中的循环依赖关系
- 修复循环依赖项 c++17 标头
- 涉及全局对象的循环依赖C++
- 循环依赖,在继承类的情况下使用覆盖方法
- Wt::D bo 中的循环依赖关系
- 在包含窗口标头时难以解决循环依赖关系问题
- 解决循环依赖关系 c++ 的想法
- C++循环依赖关系,未声明的标识符
- C++ 中的循环依赖关系问题
- 错误 C2512 视觉C++(并且不是循环依赖项)
- CMake 外部和内部静态库的循环依赖关系
- 正在从继承中解析循环依赖项
- "std::shared_ptr"循环依赖关系是如何导致问题的
- 纯引用而不是weak_ptr来打破循环依赖关系
- "invalid use of incomplete type" .解决循环依赖关系
- 如何避免模板方法的循环依赖
- 循环依赖结构,使用前向声明时结构的错误重定义