从迭代器调用函数(Calling functions from an iterator)
我的
Game
类的drawScreen()
函数出错了。void Game::drawScreen() { window->clear(); std::vector<sf::Drawable*>::iterator itr; for(int i = 0; i <= window->getSize().y; i++) { for(itr=drawableStack.begin(); itr!=drawableStack.end(); drawableStack.pop_back()) { if(**itr.getPosition().y == i) { window->draw(**itr); } } } window->display(); }
声明了可绘制堆栈
std::vector<sf::Drawable*> drawableStack;
错误发生在
if(**itr.getPosition().y == i)
它不喜欢
**itr.getPosition()
,我不确定在它的位置使用什么。 此外,此功能的目标是从屏幕顶部向下绘制,以便首先绘制“更远”的东西,并在它们之上绘制更接近前景的对象。 如果这似乎不是一个有效的方法,让我知道什么会更好。 我担心当绘制一堆物体时,这可能会变慢。I'm getting an error in the
drawScreen()
function of myGame
class.void Game::drawScreen() { window->clear(); std::vector<sf::Drawable*>::iterator itr; for(int i = 0; i <= window->getSize().y; i++) { for(itr=drawableStack.begin(); itr!=drawableStack.end(); drawableStack.pop_back()) { if(**itr.getPosition().y == i) { window->draw(**itr); } } } window->display(); }
The drawable stack is declared
std::vector<sf::Drawable*> drawableStack;
The error is at
if(**itr.getPosition().y == i)
It doesn't like the
**itr.getPosition()
and I'm not sure what to use in its place. Also, the goal of this function is to draw from the top of the screen down, so that things "farther away" are drawn first and objects closer to the foreground are drawn on top of them. If this doesn't seem like an efficient method of doing that let me know what would be better. I'm concerned that this may be slower when there's a bunch of objects being drawn.
原文:https://stackoverflow.com/questions/19144423
最满意答案
大多数书籍都解释了将Models放在Models文件夹中是一个约定优于配置。 他们还声明ASP.NET MVC框架假定开发人员将Models放在该文件夹中。
这是错的。 asp.net-mvc唯一一次使用文件夹结构并且需要其配置(显式地或通过约定)是在查找视图时。 控制器的约定以后缀“Controller”结束,而型号没有。 您可以随意将模型放置在任何您喜欢的地方。
Most books explain that placing Models in Models folder is a Convention over Configuration. They also state that ASP.NET MVC Framework assumes developers to put Models in that folder.
This is wrong. The only time asp.net-mvc uses folder structure and needs its configuration (explicitly or by convention) is when finding Views. Controllers have convention to end with suffix "Controller" and Models do not have any. You can feel free to place models where ever you like.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
要检查的一件事是您已将类放在区域(或任何文件夹)中的正确文件夹中。 现在文件夹不是逻辑上的conatiner。 如果您在这些文件夹中放置了类并且它们没有通过intellisense出现,请确保namespace与您的文件夹结构相匹配。 在解决方案\项目之间移动代码时,这很常见。 One thing to check would be that you have placed classes in the correct folders in your Area (or any folders). Now f ...
-
大多数书籍都解释了将Models放在Models文件夹中是一个约定优于配置。 他们还声明ASP.NET MVC框架假定开发人员将Models放在该文件夹中。 这是错的。 asp.net-mvc唯一一次使用文件夹结构并且需要其配置(显式地或通过约定)是在查找视图时。 控制器的约定以后缀“Controller”结束,而型号没有。 您可以随意将模型放置在任何您喜欢的地方。 Most books explain that placing Models in Models folder is a Convention ...
-
你应该明白的第一件事是MVC中的Model不是一个类/对象。 它是一个由众多对象组成的图层。 我懒得再次做同样的歌曲 ,所以请阅读此评论 (跳到“旁注”部分)。 你混淆的根源在于,你认识到你称之为“模型”的一组课程中有两种不同的责任。 实际上,您负责业务逻辑的类实例(如您的UserModel类)以及一个名为“ORM”的单独事件,该事件加载和存储内容。 而且你有身份验证,这不适合任何一个组。 我会选择这样的结构: /application /modules /public ...
-
据我所知,您需要命名空间模型以便加载它们。 使用发生器: > ./script/generate model Customer::Address 将在app/models/customer/address.rb创建模型 class Customer::Address end 它将递归加载,但为了让rails找到它,它需要有与该路径对齐的名称空间。 公平的警告,当你使用发生器(至少在轨道2.3.5和更低的是我所测试过的)。 它将以customer_addresses创建表名,但默认情况下,该模型仍会查找 ...
-
在“models.py”中动态地声明模型以外的模型(Declaring models elsewhere than in “models.py” AND dynamically)[2023-08-13]
Django知道在项目中任何地方定义的所有模型,因此您只需确保执行它们所定义的代码。 当您导入定义模型的模块时,通常会发生这种情况。 另一件重要的事情是,模型中的Meta类的app_label属性需要设置为应用程序的包名称(在您的示例中为myapp )。 这是必要的,因为syncdb只会在INSTALLED_APPS设置中列出的应用程序中安装数据库中的模型。 关于问题中描述的设置,您需要: 确保导入定义模型的模块 将模型的Meta类中的app_label属性设置为myapp 将myapp放入INSTALLE ... -
不同的模型与设计(different Models with devise)[2022-04-18]
要生成多个模型(例如,用户和管理员),只需使用: > rails generate devise User > rails generate devise Admin 要生成不同的视图集: 在config/initializers/devise.rb文件中设置config.scoped_views = true 。 您现在可以根据users/sessions/new和admins/sessions/new等角色获得视图。 如果在范围内未找到任何视图,Devise将使用devise / sessions / ... -
使用代理模型(Using proxy models)[2022-06-17]
mapToSource应该从源模型返回一个索引: virtual QModelIndex mapToSource(const QModelIndex & proxyIndex) const { return sourceModel()->index(proxyIndex.row(),proxyIndex.column()); } 我测试了那段代码: #include#include "file_proxy_model.h" int main(int argc, char *ar ... -
这可能是一个辅助对象,然后应该进入helpers文件夹。 这也可能是模型的一部分。 你应该阅读一下“ 脂肪模型,瘦的控制器 ”策略。 一个快速的谷歌带来了这些: devinterface.com goodcoresoft.com This is presumably a helper object, and should then go into the helpers folder. It is also possible that this should be part of the model. Yo ...
-
控制器/ authenticate.js var app = require("express"); var router = app.Router(); var model = require("../models/authenticate.js"); router.get('/login',function(req,res){ res.send(model.authenticate()); }); module.exports = router; var model = ...