missing type specifier - int assumed. Note: C++ does not support default-int on function in .h file
我正在关注Packt Publishing在" SFML游戏开发"中概述的教程。 在第4章中,我遇到了很多错误,最明显的是"缺少类型说明符-假定为int。注意:C ++不支持default-int"。 这是我引用的头文件和源文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #pragma once #include #include #include <vector> #include <SFML\\Graphics.hpp> #include"Category.h" #include"Command.h" class SceneNode : public sf::Transformable, public sf::Drawable, private sf::NonCopyable { public: typedef std::unique_ptr<SceneNode> Ptr; public: SceneNode(); void attachChild(Ptr); Ptr detachChild(const SceneNode&); void update(sf::Time); sf::Transform getWorldTransform() const; sf::Vector2f getWorldPosition() const; unsigned int getCategory() const; void onCommand(const Command&, sf::Time); private: virtual void draw(sf::RenderTarget&, sf::RenderStates) const; virtual void drawCurrent(sf::RenderTarget&, sf::RenderStates) const; virtual void updateCurrent(sf::Time); void updateChildren(sf::Time); private: std::vector<Ptr> mChildren; SceneNode* mParent; }; #include"SceneNode.h" SceneNode::SceneNode() : mChildren(), mParent(nullptr) { } void SceneNode::attachChild(Ptr child) { child->mParent = this; mChildren.push_back(std::move(child)); } SceneNode::Ptr SceneNode::detachChild(const SceneNode& node) { auto found = std::find_if(mChildren.begin(), mChildren.end(), [&] (Ptr& p) -> bool { return p.get() == &node; }); assert(found != mChildren.end()); Ptr result = std::move(*found); result->mParent = nullptr; mChildren.erase(found); return result; } void SceneNode::draw(sf::RenderTarget& target, sf::RenderStates states) const { states.transform *= getTransform(); drawCurrent(target, states); for(auto itr = mChildren.begin(); itr != mChildren.end(); ++itr) { (*itr)->draw(target, states); } } void SceneNode::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const { } void SceneNode::updateCurrent(sf::Time dt) { } void SceneNode::update(sf::Time dt) { updateCurrent(dt); updateChildren(dt); } void SceneNode::updateChildren(sf::Time dt) { for(auto itr = mChildren.begin(); itr != mChildren.end(); ++itr) { (*itr)->update(dt); } } sf::Transform SceneNode::getWorldTransform() const { sf::Transform transform = sf::Transform::Identity; for(const SceneNode* node = this; node != nullptr; node = node->mParent) { transform = node->getTransform() * transform; } return transform; } sf::Vector2f SceneNode::getWorldPosition() const { return getWorldTransform() * sf::Vector2f(); } unsigned int SceneNode::getCategory() const { return Category::Scene; } void SceneNode::onCommand(const Command& command, sf::Time dt) { if(command.category & getCategory()) { command.action(*this, dt); for(auto itr = mChildren.begin(); itr != mChildren.end(); ++itr) { (*itr)->onCommand(command, dt); } } } |
该错误专门在第23行上:
1 | void onCommand(const Command&, sf::Time); |
有任何想法吗?
我猜文件" Command.h"也包含此文件...如果是这种情况,
只需在
1 2 3 4 5 6 | class Command; class SceneNode : public sf::Transformable, public sf::Drawable, private sf::NonCopyable { // etc. }; |
您会看到一个错误,因为编译器还没有看到类型
请参阅我对这个问题的回答,以获得更详细的解释。 (仅供参考,Objective-C中的
这个特定的编译器错误通常意味着您已经以某种方式搞砸了变量声明,通常是通过使用未知类型或以其他方式使行格式错误。
由于