小编Bar*_*icz的帖子

我可以在代码中明确禁用已弃用的OpenGL函数吗?

我最近开始编写使用OpenGL较新实现的代码.我注意到,但是在较新的OpenGL实现中,旧的函数被认为是不推荐的.如果我只想使用正确的功能,有没有办法禁用它们?

c++ opengl opengl-3

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

如何使用通用视图在视图中设置模型的字段?

我有一个模型,有一个作者ForeignKey,如下:

class Appointment(models.Model):
    # ...
    author = models.ForeignKey(User)
Run Code Online (Sandbox Code Playgroud)

我希望在author为当前登录用户创建约会时自动设置该字段.换句话说,作者字段不应出现在我的Form类中:

class AppointmentCreateForm(ModelForm):
    class Meta:
        model = Appointment
        exclude = ('author')
Run Code Online (Sandbox Code Playgroud)

有两个问题:

  1. 如何访问通用CreateView中的表单并设置author
  2. 如何告诉表单保存排除字段以及从用户输入读取的值?

django django-generic-views

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

我不明白使用return*这个"整体"

我无法弄清楚我正在阅读的书的下半部分究竟是什么.

//this function supposed to mimic the += operator
Sales_data& Sales_data::combine(const Sales_data &rhs)
{
    units_sold += rhs.units_sold; // add the members of rhs into
    revenue += rhs.revenue;  // the members of ''this'' object
    return *this; // return the object on which the function was called
}

int main()
{
    //...sth sth

    Sales_data total, trans; 
    //assuming both total and trans were also defined...
    total.combine(trans);
    //and here the book says:
    //we do need to use this to access the object as a …
Run Code Online (Sandbox Code Playgroud)

c++

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

"表达式必须具有类类型"错误是什么意思?

#include <cstdlib>
using namespace std;

int main()
{
    int arrayTest[512];
    int size = arrayTest.size();
    for(int a = 0;a<size;a++)
    {
         //stuff will go here
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么,因为计划是用一些数字填充数组

c++ arrays

3
推荐指数
2
解决办法
2万
查看次数

如何运行通过命令参数传递给解释器的haskell代码?

在其他方法中,有一些最常用的方法来运行haskell程序:

  • ghci,加载文件,从shell手动运行main
  • runhaskell file.hs
  • ghc file.hs && ./file

但是,我无法找到如何从标准输入/命令参数运行简单代码.

例如,标准的Lua解释器将允许您执行:

$ lua -e "print (2+2)"
4
Run Code Online (Sandbox Code Playgroud)

对于常见的Haskell平台环境,上述内容是什么?

stdin haskell

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

线性类型如何防止这种"重复"的实现?

我最近阅读了Tweag.IO关于线性类型的帖子,这是一个有用的工具,用于表达仅使用(确切)一次的参数.他们提供以下示例:

dup :: a ? (a,a)
dup x = (x,x)
Run Code Online (Sandbox Code Playgroud)

现在,也许我误解了这个想法,但为什么不能用以下方法来规避:

dup' :: a ? (a,a)
dup' x = (y,y)
  where
    y = x
Run Code Online (Sandbox Code Playgroud)

这篇文章特别提到了论点.这是否也延伸到函数中的所有绑定?

haskell types linear-types

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

如何链接到本地​​ Haskell 库?

当前有两个带有堆栈和 cabal 文件的项目(我使用堆栈来构建),一个是名为 test 的 exe,另一个是名为 testlib 的库。我想在测试项目中使用 testlib,我该怎么做才能让堆栈知道 testlib 是一个自定义库以及如何找到它?

-- projects/test/test.yaml
-- projects/testlib/testlib.yaml
Run Code Online (Sandbox Code Playgroud)

haskell haskell-stack

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

从以类方法编写的 lambda 函数访问类字段

代码示例可能更具描述性:

class CDialog
{
    CButton* ButtonPtr;
    bool m_Visible;
    void SomeMethod ();
}

class CButton
{
public:
    std::tr1::function<void(void)> Function;
}

void CDialog::SomeMethod()
{
    ButtonPtr = new CButton;
    std::tr1::function<void(void)> TempF = [this]
    {
        this->m_Visible = false;
    };
    ButtonPtr->Function = TempF;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试调用 TempF 时,它似乎修改了 m_Visible 变量的一些副本而不是实际值。我想问一下它是否是默认行为,以及是否有某种方式可以这样使用它。我的修补程序使用了指针,效果很好,但我很好奇是否可以完成。

编辑:我创建了一个最小的例子,它确实有效。

EDIT2:修复了不调用函数的错误。

EDIT3:更改为更准确地匹配我的问题。假设单击按钮时调用了 CButton 的函数,并确认。还是不行。

EDIT4:花了一些时间用调试器检查它。创建函数时使用的“this”指针的值与调用函数时使用的值不同。那么我做错了什么吗?

EDIT5:在我的代码中发现错误,修复并结合答案解决了我的问题。感谢大家的回复,感谢你们,我今天学到了一些新东西!

c++ lambda c++11

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

运算符重载和无效操作数问题到二进制表达式

我创建了一个类Foo,我重载了运算符,< > <= >= != and =现在我有这两个代码,两者都应该这样做,但只有1个工作:

这有效:

Foo foo = Foo("1");
if (foo <= something->foo) { ...
Run Code Online (Sandbox Code Playgroud)

这不起作用:

if (Foo("1") <= something->foo) { ...
Run Code Online (Sandbox Code Playgroud)

第二个版本中的错误是:

二进制表达式的操作数无效.候选函数不可行:期望第一个参数的l值

它是什么意思,为什么它不起作用?

c++

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

想要删除Lua中parantheses中字符串之间的空格

我试图删除parantheses中的字符串之间的空格.但是它给出了函数的地址.

str = "1791 (AR6K Async) S 2 0 0 0 -1 2129984 0 0 0 0 0 113 0 0 20 0 1 0 2370 0 0 4294967295 0 0 0 0 0 0 0 2147483647 0 3221520956 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0"

local word = str:gmatch("%(%S+)%" , "")
print(word)
Run Code Online (Sandbox Code Playgroud)

在上面这个字符串中,我只想要除了paranthesis空间以外的所有东西.我试图得到像下面的输出没有任何空格的paranthesis.

"1791 (AR6KAsync) S 2 0 0 0 -1 2129984 0 0 0 0 0 113 0 …
Run Code Online (Sandbox Code Playgroud)

string lua lua-table

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