编辑:这个问题可能会使用更合适的标题.随意在评论中提出建议.
在使用带有大类集的C++时,我曾遇到const一种麻烦的情况,不是因为它的功能,而是因为它有一个非常简单的定义.它对整数或字符串的适用性是显而易见的,但对于更复杂的类,通常有多个属性可以彼此独立地修改.我想很多人都被迫了解mutable关键字可能会有类似的挫折感.
对我来说最明显的例子是矩阵类,表示3D变换.矩阵将表示平移和旋转,其中每个都可以在不修改另一个的情况下进行更改.想象一下以下类和函数假设添加'多属性const'.
class Matrix {
void translate(const Vector & translation) const("rotation");
void rotate(const Quaternion & rotation) const("translation");
}
public void spin180(const("translation") & Matrix matrix);
public void moveToOrigin(const("rotation") & Matrix matrix);
Run Code Online (Sandbox Code Playgroud)
或者想象一下预定义的const关键字,比如"_comparable",它允许您定义随意修改对象的函数,只要您保证不会更改任何会影响对象排序顺序的内容,从而简化了对已排序容器中对象的使用.
这种功能的优点和缺点是什么?你能想象在你的代码中实际使用它吗?使用当前的const关键字功能是否有一种很好的方法来实现这种功能?
记住
const我希望这是一个严格的编译时功能.const自切片泥以来是最愚蠢的事情,我会把它看成是你对此有同感.无需发帖,谢谢.编辑:回应SBK关于会员加价的评论,我建议你没有.对于标记为const的类/成员,它的工作方式与以往一样.对于标记为const("foo")的任何内容,它将所有成员视为可变,除非另有标记,将其留给类作者以确保其功能与广告一样有效.此外,在内部表示为2D数组的矩阵中,您不能将单个字段标记为const或非const用于平移或旋转,因为所有自由度都在单个变量声明中.
我有一个带有一堆图形的git项目(.jpg,.png,.tiff等).图形扩展在我的.gitignore中(这可以改变),因为我不需要对图形进行版本化(负责图形的部门有版本提示并跟踪他们自己对图形的更改).但是,当我推送时,似乎只有被跟踪的内容才会进入存储库.我需要使用存储库推送图形,但我不想跟踪图形文件,我该怎么做(或者甚至可能)?
我想创建一堆记录(RWell)并按特定顺序将它们存储在一个数组中.然后我想创建一个新的数组(不同的布局)并重新排列其中的记录.当然,我不想在RAM中复制数据,所以我在第二个数组中应该将指针放在第一个数组中的记录中.但是,我做不到.任何人都可以告诉我们下面的代码有什么问题?谢谢
Type
RWell= record
x: string;
i: integer;
end;
PWell= ^RWell;
RWellArray= Array[0..12, 0..8] of RWell;
procedure TClass1.CreateWells
var
WellMX: RWellArray;
begin
{ should I initialize the WellXM here? }
{ note: WellXM is a static array! }
other stuff
end;
var Wells: array of PWell;
procedure TClass2.AddWell(aWell: RWell);
begin
aWell.Stuff:= stuff; {aWell cannot be readonly because I need to change it here}
SetLength(Wells, Length(Wells)+ 1); { reserve memory }
Wells[High(Wells)]:= @aWell;
end;
procedure TClass3.DisplayWell;
var CurWell: RWell;
begin
CurWell:= …Run Code Online (Sandbox Code Playgroud) LINQ Groupby查询为每个唯一键创建一个新组.我想根据键值将多个组合并为一个组.
例如
var customersData = new[]
{
new { id = 1, company = "ABC" },
new { id = 2, company = "AAA" },
new { id = 3, company = "ABCD" },
new { id = 4, company = "XYZ" },
new { id = 5, company = "X.Y.Z." },
new { id = 6, company = "QQQ" },
};
var groups = from d in customersData
group d by d.company;
Run Code Online (Sandbox Code Playgroud)
假设我想在同一组中使用ABC,AAA和ABCD,在同一组中使用XYZ,XYZ.
无论如何通过LINQ查询实现这一目标?
我有一个期待两种形式的模板页面.如果我只使用一个表单,那么就像这个典型的例子一样好:
if request.method == 'POST':
form = AuthorForm(request.POST,)
if form.is_valid():
form.save()
# do something.
else:
form = AuthorForm()
Run Code Online (Sandbox Code Playgroud)
但是,如果我想使用多个表单,我如何让视图知道我只提交其中一个表单而不是另一个表单(即它仍然是request.POST但我只想处理提交的表单事情)吗?
这是该解决方案基于这样的答案expectedphrase和bannedphrase是不同形式和不同的提交按钮的名称expectedphraseform和bannedphraseform是形式.
if request.method == 'POST':
if 'bannedphrase' in request.POST:
bannedphraseform = BannedPhraseForm(request.POST, prefix='banned')
if bannedphraseform.is_valid():
bannedphraseform.save()
expectedphraseform = ExpectedPhraseForm(prefix='expected')
elif 'expectedphrase' in request.POST:
expectedphraseform = ExpectedPhraseForm(request.POST, prefix='expected')
if expectedphraseform.is_valid():
expectedphraseform.save()
bannedphraseform = BannedPhraseForm(prefix='banned')
else:
bannedphraseform = BannedPhraseForm(prefix='banned')
expectedphraseform = ExpectedPhraseForm(prefix='expected')
Run Code Online (Sandbox Code Playgroud) 我想自动构建一个flex库项目而不是当前进程,这涉及我们的一个开发人员在他的机器上编译它然后我们检查生成的.swc文件.这很糟糕.
我是从Java开发人员的角度来看这个,所以我很难掌握Flex Builder 3应用程序中提供的编译工具,但这就是我已经拥有的:
<mxmlc/>和执行<compc/>任务.我想要的是一个ant脚本,它将完成以下步骤:
到目前为止我有这个:
<target name="compile-component" depends="init">
<compc output="${DEPLOY_DIR}/${SWC_NAME}.swc">
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${SRC_DIR}"/>
</compc>
</target>
Run Code Online (Sandbox Code Playgroud)
但是,它不包括任何内容:
[compc] Loading configuration file /Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/flex-config.xml
[compc] Adobe Compc (Flex Component Compiler)
[compc] Version 3.2.0 build 3958
[compc] Copyright (c) 2004-2007 Adobe Systems, Inc. All rights reserved.
[compc]
[compc] Error: nothing was specified to be included in the library
[compc]
[compc] Use 'compc -help' for information about using the command line.
Run Code Online (Sandbox Code Playgroud)
看起来我需要枚举我想要包含在库中的每个类,这是......荒谬的.肯定有更好的办法.我该怎么做呢?
我希望在PreviewTextInput处理程序中创建一个新控件并将焦点设置为它.但即使在新控件上调用Focus()之后,光标仍然在旧文本框中.处理程序UserControl_PreviewTextInput在UserControl上注册,如果这很重要,则包含此文本框.
private void UserControl_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
CodeLineControl el = new CodeLineControl();
container.Children.Insert(idx+1, el);
el.innerTextBox.Focus();
}
Run Code Online (Sandbox Code Playgroud)
CodeLineControl定义如下(简化):
<UserControl ..>
<DockPanel Name="codeline" Background="AntiqueWhite" >
<TextBox Name="innerTextBox"/>
</DockPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
Focus()是否存在一些限制?我不允许将Focus()从PreviewTextInput处理程序中移出TextBox吗?我不能把注意力集中在新创建的元素上吗?
我正在使用noobie应用程序从数据库中提取一些日期,然后一年后发送警报(使用cron).到目前为止,我有点挣扎,我正在尝试制作一个能够完成我的数学工作的页面.
到目前为止,我已经整天调试并在教程后阅读教程,但仍然出现错误.很沮丧:)
我的代码看起来像这样....
<?php
$con = mysql_connect("localhost","root", "etc");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$result = mysql_query('SELECT CheckDate FROM Data') or exit(mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
$validfromdate = CheckDate;
$alert=strtotime("+1 year", $validfromdate);
echo $alert;
?>
Run Code Online (Sandbox Code Playgroud) 是否可以通过COM互操作在.NET对象上调用静态方法?
我知道我可以写一个包装类.如果我不想那样做怎么办?