我最近开始编写使用OpenGL较新实现的代码.我注意到,但是在较新的OpenGL实现中,旧的函数被认为是不推荐的.如果我只想使用正确的功能,有没有办法禁用它们?
我有一个模型,有一个作者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)
有两个问题:
author?我无法弄清楚我正在阅读的书的下半部分究竟是什么.
//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) #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)
我在这里做错了什么,因为计划是用一些数字填充数组
在其他方法中,有一些最常用的方法来运行haskell程序:
ghci,加载文件,从shell手动运行mainrunhaskell file.hsghc file.hs && ./file但是,我无法找到如何从标准输入/命令参数运行简单代码.
例如,标准的Lua解释器将允许您执行:
$ lua -e "print (2+2)"
4
Run Code Online (Sandbox Code Playgroud)
对于常见的Haskell平台环境,上述内容是什么?
我最近阅读了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)
这篇文章特别提到了论点.这是否也延伸到函数中的所有绑定?
当前有两个带有堆栈和 cabal 文件的项目(我使用堆栈来构建),一个是名为 test 的 exe,另一个是名为 testlib 的库。我想在测试项目中使用 testlib,我该怎么做才能让堆栈知道 testlib 是一个自定义库以及如何找到它?
-- projects/test/test.yaml
-- projects/testlib/testlib.yaml
Run Code Online (Sandbox Code Playgroud) 代码示例可能更具描述性:
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:在我的代码中发现错误,修复并结合答案解决了我的问题。感谢大家的回复,感谢你们,我今天学到了一些新东西!
我创建了一个类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值
它是什么意思,为什么它不起作用?
我试图删除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)