首页 \ 问答 \ 从迭代器调用函数(Calling functions from an iterator)

从迭代器调用函数(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 my Game 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
更新时间:2021-03-05 10:03

最满意答案

大多数书籍都解释了将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.

相关问答

更多
  • 要检查的一件事是您已将类放在区域(或任何文件夹)中的正确文件夹中。 现在文件夹不是逻辑上的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创建表名,但默认情况下,该模型仍会查找 ...
  • Django知道在项目中任何地方定义的所有模型,因此您只需确保执行它们所定义的代码。 当您导入定义模型的模块时,通常会发生这种情况。 另一件重要的事情是,模型中的Meta类的app_label属性需要设置为应用程序的包名称(在您的示例中为myapp )。 这是必要的,因为syncdb只会在INSTALLED_APPS设置中列出的应用程序中安装数据库中的模型。 关于问题中描述的设置,您需要: 确保导入定义模型的模块 将模型的Meta类中的app_label属性设置为myapp 将myapp放入INSTALLE ...
  • 要生成多个模型(例如,用户和管理员),只需使用: > 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 / ...
  • 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 = ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)