常量引用如何产生影响?(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.

相关问答

更多

django模板:扩展模板能够在父页面中更改css吗?(django template: Is extended template able to change css in parent page?)

在主要模板中: <body class="{% block body_class %}{% endblock %}"> ... </body> 然后在子模板中,只需定义块: {% block body_class %} my_new_body_css_class {% endblock %} 这将呈现<body class="my_new_body_css_class">...</body> ,您必须在链接的CSS中定义此类。 In the main template: <body class...

寻找提供django模板的资源(Looking for a resource which provides django templates [closed])

过去,我有过一些运气,像OpenDesigns和FreeCSSTemplates等网站 - 他们提供(主要)CC许可的HTML模板; 你必须自己添加Django模板。 正如詹姆斯指出的那样,他们中的大多数都会让你开始运转,但你几乎总是想要更进一步。 我的建议是:建立一个可重复使用的模板库(使用上述站点的内容),获得真正舒适的HTML和CSS编辑(因为您将编辑HTML和CSS),然后找到一些kickass设计师(最好是本地),并获得与他们真正友好。 也许你可以交易优惠; 你可以免费为他们做一些编码工...

使用Django模板标签的Mako模板(Mako templates using Django template tags)

我很少使用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 M...

django模板中的函数(functions in django templates)

不.Django模板的想法是它们只显示信息(或多或少)。 必须在别处定义更复杂的构造(如函数)。 但是,您可以创建自己的模板标签或模板过滤器(在Python代码中),然后在模板中使用它们。 他们有点像功能。 但是,他们的定义不在您的模板中。 你可以在django 文档中阅读它 No. The idea of Django templates is that they only display information (more or less). More complicated construc...

django模板可以找到它的命名url,还是基本模板可以知道哪个模板正在扩展它?(Can a django template find out its named url or can a base template know which template is extending it?)

您可以使用模板继承和块来管理它。 你的base.html定义了一个名为login的块,它围绕着用于登录的HTML - 你的login.html用空版本覆盖那个块: base.html文件: {% block login %} ... login form here ... {% endblock %} {% block main %} {% endblock %} 的login.html: {% extends "base.html" %} {% block login %} {% ...

哪个Django模板布局更好?(Which Django template layout is better? [closed])

这可能取决于您的目的。 对于大多数目的,第一个示例将最有效。 您的base.html将包含许多特定于网站的内容,您不希望在每个base_app.html模板中重复这些base_app.html 。 如果您要制作要与其他人共享的可重用应用程序,那么最好使用第二个示例。 这样,使用您的应用的用户就不需要base.html模板来启动和运行您的应用。 它更“全包”。 这基本上就是那些文档所说的。 一般的建议是使用第一种方法, 除非你是开源并把它放在PyPi或其他东西上。 即使你想让一个包可以重复使用(也就...

Django模板 - 停止处理模板(Django Template - Stop processing template)

您可以使用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项目中很容易地使用ji...

django如何使用模板(django how to work with templates)

如上所述,您必须执行以下操作: 当您使用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 whi...

在django中实现shopify模板(Implement shopify templates in django)

将.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 extens...

根据我的设计更改django扩展模板以提供所有提供的模板(Changing django extended template to have all provided templates according to my design)

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

相关文章

更多

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

Become a Master Designer: Rule Three: Contrast, Contrast, Contrast

Part Three of Seven Easy Principles to Becoming a M ...

trouble is a friend

trouble will find you no matter where you go, oh ...

Book Report: THE SOUL OF A NEW MACHINE

Book Report: THE SOUL OF A NEW MACHINE Zhengdong Zh ...

Spring Data: a new perspective of data operations

Spring Data: a new perspective of data operations ...

How to Start a Business in 10 Days

With an executive staffing venture about to open, a ...

A Great List of Windows Tools

Windowsis an extremely effective and a an efficient ...

Create a Bootable MicroSD Card

http://gumstix.org/create-a-bootable-microsd-card.h ...

每日英语:Man Without a Country

'I'm like a proud son of China,' Taiwan-born direct ...

7.trouble is a friend(Lenka)

Trouble will find you no matter where you go, oh oh ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本