首页 \ 问答 \ 常量引用如何产生影响?(How does constant reference makes a difference?)

常量引用如何产生影响?(How does constant reference makes a difference?)

我不明白为什么以下代码不起作用:

#include <iostream>
using namespace std;

class PayOff{};
class PayOffCall : public PayOff{};

class PayOffBridge{
public:
    PayOffBridge( PayOff& innerPayOff){};
};

class VanilaOption{
public:
   VanilaOption(PayOffBridge& ThePayOff_){cout << " test " <<endl;}
};


int main () {
PayOffCall thePayOff;
VanilaOption theOption(thePayOff);
  return 0;
}

出于某种原因,在VanilaOption类(下面的代码)中更改对const的引用使其工作,有人可以解释它是如何工作的吗? 我得到的错误是: 没有匹配函数来调用'VanilaOption :: VanilaOption(PayOffCall&)'

但它并没有帮助我弄明白。

class VanilaOption{
public:
   VanilaOption(const PayOffBridge& ThePayOff_){cout << " test " <<endl;}
};

我也不明白为什么在PayOffBridge引用预期有效时通过PayOffCall引用,有人可以帮我解决这个问题吗?

谢谢!


I dont understand why the following code doesn't work:

#include <iostream>
using namespace std;

class PayOff{};
class PayOffCall : public PayOff{};

class PayOffBridge{
public:
    PayOffBridge( PayOff& innerPayOff){};
};

class VanilaOption{
public:
   VanilaOption(PayOffBridge& ThePayOff_){cout << " test " <<endl;}
};


int main () {
PayOffCall thePayOff;
VanilaOption theOption(thePayOff);
  return 0;
}

For some reason changing the reference to const in VanilaOption class (code below) makes it work, can someone explain how does it work? The error I get is: no matching function for call to 'VanilaOption::VanilaOption(PayOffCall&)'

but it doesn't help me to figure it out.

class VanilaOption{
public:
   VanilaOption(const PayOffBridge& ThePayOff_){cout << " test " <<endl;}
};

I also don't understand why passing PayOffCall reference when PayOffBridge reference is expected works, can someone help me out on this?

Thank you!


原文:https://stackoverflow.com/questions/34583750
更新时间:2023-11-07 12:11

最满意答案

简答:您必须编写自己的模板。

更长的答案:

Django确实包含了一些模板,但这些模板都仅用于管理应用程序。 auth视图默认使用'registration / some_template.html',这些模板都存在于admin应用程序中(请参阅https://github.com/django/django/tree/master/django/contrib/admin/templates/registration )。 auth视图都支持您可以在URLConf中提供的template关键字参数,以便您可以指定要使用的模板。

将管理模板视为您在编写自己的模板时可以使用的参考,但不是您想要直接使用的参考。


Short answer: You have to write your own templates.

Longer answer:

Django does include some templates, but these are all intended solely for the admin application. The auth views default to using 'registration/some_template.html', and those templates all live in the admin app ( see https://github.com/django/django/tree/master/django/contrib/admin/templates/registration). The auth views all support a template keyword argument that you can supply in your URLConf, so that you can specify which of your own templates to use.

Think of the admin templates as a reference that you can use when writing your own templates, but not as something you're meant to use directly.

相关问答

更多
  • 在主要模板中: ... 然后在子模板中,只需定义块: {% block body_class %} my_new_body_css_class {% endblock %} 这将呈现... ,您必须在链接的CSS中定义此类。 In the main template:
    过去,我有过一些运气,像OpenDesigns和FreeCSSTemplates等网站 - 他们提供(主要)CC许可的HTML模板; 你必须自己添加Django模板。 正如詹姆斯指出的那样,他们中的大多数都会让你开始运转,但你几乎总是想要更进一步。 我的建议是:建立一个可重复使用的模板库(使用上述站点的内容),获得真正舒适的HTML和CSS编辑(因为您将编辑HTML和CSS),然后找到一些kickass设计师(最好是本地),并获得与他们真正友好。 也许你可以交易优惠; 你可以免费为他们做一些编码工作,作为回 ...
  • 我很少使用Mako,但是如果你可以包含任意的Python代码,那么你总是可以在那里嵌入模板渲染函数。 <% tpl = """{% load facebook_tags %}{% facebook_button %}{% facebook_js %}""" from django.template import Template, Context t = Template(tpl) t.render(Context()) %> I've hardly used Mako, ...
  • 不.Django模板的想法是它们只显示信息(或多或少)。 必须在别处定义更复杂的构造(如函数)。 但是,您可以创建自己的模板标签或模板过滤器(在Python代码中),然后在模板中使用它们。 他们有点像功能。 但是,他们的定义不在您的模板中。 你可以在django 文档中阅读它 No. The idea of Django templates is that they only display information (more or less). More complicated constructs (l ...
  • 您可以使用模板继承和块来管理它。 你的base.html定义了一个名为login的块,它围绕着用于登录的HTML - 你的login.html用空版本覆盖那个块: base.html文件: {% block login %} ... login form here ... {% endblock %} {% block main %} {% endblock %} 的login.html: {% extends "base.html" %} {% block login %} {% endbl ...
  • 这可能取决于您的目的。 对于大多数目的,第一个示例将最有效。 您的base.html将包含许多特定于网站的内容,您不希望在每个base_app.html模板中重复这些base_app.html 。 如果您要制作要与其他人共享的可重用应用程序,那么最好使用第二个示例。 这样,使用您的应用的用户就不需要base.html模板来启动和运行您的应用。 它更“全包”。 这基本上就是那些文档所说的。 一般的建议是使用第一种方法, 除非你是开源并把它放在PyPi或其他东西上。 即使你想让一个包可以重复使用(也就是在你正在 ...
  • 您可以使用jinaj2模板化该视图(或整个项目),它支持/ elif / else分支: {% if data.some_state %} Display some markup {% elif data.some_state_2 %} State 2 different view {% elif data.process_data %} Display some list of data {% endif %} 有几个不同的软件包可以在django项目中很容易地使用jinja2, ...
  • 如上所述,您必须执行以下操作: 当您使用Django时,您必须告诉它您正在使用哪些设置。 通过使用环境变量DJANGO_SETTINGS_MODULE 。 DJANGO_SETTINGS_MODULE的值应该是Python路径语法,例如mysite.settings 。 请注意,设置模块应位于Python导入搜索路径中。 As noted here, you have to do the following: When you use Django, you have to tell it which se ...
  • 将.liquid文件扩展名更改为.html以及任何带有.liquid扩展名的css和js以及.html。 确保您的上下文来自python代码,因为您提到的模板要求您创建shopify ID,然后它将从shopify处理器呈现上下文。 有一些方法可以使python上下文处理器与.liquid文件一起使用,但我不推荐它。 您将使项目复杂化。 Change .liquid file extension to .html and for any css and js with .liquid extension t ...
  • 简答:您必须编写自己的模板。 更长的答案: Django确实包含了一些模板,但这些模板都仅用于管理应用程序。 auth视图默认使用'registration / some_template.html',这些模板都存在于admin应用程序中(请参阅https://github.com/django/django/tree/master/django/contrib/admin/templates/registration )。 auth视图都支持您可以在URLConf中提供的template关键字参数,以便您 ...

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)