标签: overloading

Django 类型的重载视图

这怎么可能在 Django 中创建重载视图?问题是我有一个观点,它可以只接受一个参数,也可以不接受。如果有参数,它将传递给视图。

让我们展示我正在尝试做的事情

视图.py

def member_list(request,message):
    memberList = Member.objects.all()
    return render_response(request, 'user/member_list.html', {'memberList': memberList,    'message':message })

def member_list(request,message):
    memberList = Member.objects.all()
    return render_response(request, 'user/member_list.html', {'memberList': memberList,    'message':message })
Run Code Online (Sandbox Code Playgroud)

网址.py

(r'^member/list/$', 'views.member_list'),
(r'^member/list/(?P<message>[-\w]+)/$', 'views.member_list'),
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

谢谢

django parameters overloading django-views

1
推荐指数
1
解决办法
791
查看次数

为什么 Linux C API 'open' 支持函数重载?

根据Linux 手册页,Linux C APIopen有两个原型如下:

int open(const char *pathname, int oflags);
int open(const char *pathname, int oflags, mode_t mode);
Run Code Online (Sandbox Code Playgroud)

让我困惑的是:

为什么 Linux C API 'open' 支持函数重载??

c linux api overloading

1
推荐指数
1
解决办法
276
查看次数

使用运算符重载时,没有运算符“&lt;&lt;”匹配这些操作数

以下尝试运算符重载时发生错误:

#include<iostream>
#include<string>
#include<ostream>
using namespace std;

class Dollar
{
private:
    float currency, mktrate, offrate;
public:
    Dollar(float);
    float getDollar() const;
    float getMarketSoums() const;
    float getofficialSoums() const;
    void getRates();

    // In the following function I was trying to overload "<<" in order to print all the data members:
    friend void operator<<(Dollar &dol, ostream &out)
    {
        out << dol.getDollar() << endl;
        out << dol.getMarketSoums() << endl;
        out << dol.getofficialSoums() << endl;
    }
};

Dollar::Dollar(float d)
{
    currency = d;
}

float Dollar::getDollar() …
Run Code Online (Sandbox Code Playgroud)

c++ overloading ostream

1
推荐指数
1
解决办法
1244
查看次数

如果委托不能重载,那么“Func”和“Action”如何有 16 个重载?

我一直在学习委托(在 C# 中),我读过的所有文章都说委托不能重载(与方法不同)。但是当我使用 'Func' 和 'Action' 方法(它们是 .NET 内置委托)时,我注意到它们已被重载:

在此处输入图片说明

这怎么可能?

.net c# delegates overloading

1
推荐指数
1
解决办法
324
查看次数

函数重载和模板

我有一个重载函数,它们的定义是相同的,只有一个参数改变。所以,我试图创建一个模板函数,但是当我调用它时,我得到了一个符号查找错误。

头文件

void func(Myobject obj);
void func(MySecondObject obj);
Run Code Online (Sandbox Code Playgroud)

源文件

template<typename T>
void func(T obj) { obj.foo(); }
Run Code Online (Sandbox Code Playgroud)

测试文件

#include "MyHeaderFile.h"

func(MySecondObject()); // symbol lookup error at runtime
Run Code Online (Sandbox Code Playgroud)

谢谢。

c++ templates overloading

1
推荐指数
1
解决办法
59
查看次数

通过争论之间的区别

大家好我写了两个代码

1.

    #include<iostream>
    using namespace std;
    void swap(int *x, int *y)
    {
        int t;
        t = *x;
        *x = *y;
        *y = t;
    }
    int main()
    {
        int a = 10, b = 20;
        cout << "value of a before swap " << a << endl;
        cout << "value of b before swap " << b << endl;
        swap(&a, &b);
        cout << "value of a after swap " << a << endl;
        cout << "value of b after swap " …
Run Code Online (Sandbox Code Playgroud)

c++ swap overloading pass-by-reference name-lookup

1
推荐指数
1
解决办法
86
查看次数

为什么这个对重载函数的调用不明确?

考虑这个程序-

#include <string>
#include <vector>
#include <set>
void fun(const std::string& val) {
}

void fun(std::vector<std::string> val) {
}

int main()
{
    std::set<std::string> example;
    fun({std::begin(example), std::end(example)});
}
Run Code Online (Sandbox Code Playgroud)

在编译时,我遇到了这些错误-

prog.cc: In function 'int main()':
prog.cc:13:49: error: call of overloaded 'fun(<brace-enclosed initializer list>)' is ambiguous
   13 |     fun({std::begin(example), std::end(example)});
      |                                                 ^
prog.cc:4:6: note: candidate: 'void fun(const string&)'
    4 | void fun(const std::string& val) {
      |      ^~~
prog.cc:7:6: note: candidate: 'void fun(std::vector<std::__cxx11::basic_string<char> >)'
    7 | void fun(std::vector<std::string> val) {
      |      ^~~
Run Code Online (Sandbox Code Playgroud)

我知道它std::string有一个构造函数重载,它接受 …

c++ templates iterator overloading initializer-list

1
推荐指数
1
解决办法
297
查看次数

未见类外的函数重载

考虑以下代码片段:

enum class Bar {
    A
};

void foo(Bar) {}

struct Baz {
    void foo() {
        foo(Bar::A);
    }
};
Run Code Online (Sandbox Code Playgroud)

它无法编译,来自 gcc 9.2 的消息是:

:12:19: error: no matching function for call to 'Baz::foo(Bar)'
 12 |         foo(Bar::A);
    |              
Run Code Online (Sandbox Code Playgroud)

我不怀疑这是一个错误,因为 clang 10 也失败了。关于这种情况,我有两个问题:

  1. 标准在哪里定义了这种重载的行为?

  2. 以这种方式指定编译器行为的可能原因是什么?

活生生的例子

c++ overloading language-lawyer name-lookup

1
推荐指数
2
解决办法
83
查看次数

你能在C中进行重载并且具有相同的函数名吗?

在Java中,当方法具有相同名称时,我们可以进行重载。我在谷歌上搜索,它说 C 不支持重载,所以我想知道是否有一种方法可以做类似于 C 中的重载的事情。

例如:

int max(int num1, int num2);
double max(double num1, num2);

int main(){
  printf(...);
  printf(...);
}

int max(int num1, int num2){
  ...
}

double max(double num1, double num2){
  ...
}
Run Code Online (Sandbox Code Playgroud)

c overloading

1
推荐指数
1
解决办法
61
查看次数

Common Lisp:是否有带有类型说明符的“标签”版本?

是否有一个 Common Lisp 构造是 to labelswhat defmethodis to defun?也就是说,我想使用labels(或类似的东西)来定义几个具有相同名称但它们接受的参数不同的局部函数,并让编译器在其中进行选择。

作为 MWE,我想实现以下功能

(defmethod write-first-item-type ((lst list))
  "Writes the type of the first item in lst."
  (labels ((write-single ()
             (format t "a single float"))
           (write-double ()
             (format t "a double float")))

    (format t "The first item is: ~A.~%"
        (cond ((eql (type-of (car lst)) 'single-float)
               (write-single))
              ((eql (type-of (car lst)) 'double-float)
               (write-double))
              (t
               (format t "unknown"))))))
Run Code Online (Sandbox Code Playgroud)

像

(defmethod write-first-item-type ((lst list))
  "Should write the type of the first …
Run Code Online (Sandbox Code Playgroud)

types overloading function common-lisp

1
推荐指数
1
解决办法
82
查看次数