请考虑以下示例.它由两个头文件组成,声明两个不同的名称空间:
// a1.h
#pragma once
#include "a2.h"
namespace a1
{
const int x = 10;
typedef a2::C B;
}
Run Code Online (Sandbox Code Playgroud)
第二个是
// a2.h
#pragma once
#include "a1.h"
namespace a2 {
class C {
public:
int say() {
return a1::x;
}
};
}
Run Code Online (Sandbox Code Playgroud)
还有一个源文件main.cpp
:
#include <iostream>
#include "a1.h"
#include "a2.h"
int main()
{
a2::C c;
std::cout << c.say() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
这样它就不会编译(尝试过GCC和MSVC).错误是a1
未声明名称空间(Windows上为C2653).如果您以main.cpp
这种方式更改包含订单:
#include "a2.h"
#include "a1.h"
Run Code Online (Sandbox Code Playgroud)
您会收到对称错误消息,即a2
未声明命名空间.
有什么问题?
我希望这不是浪费时间,但我真的一直试图解决这个问题.这是我的语法.一旦单击".remove-link"类的链接,我只想删除父div".number-row".
提前致谢
<script>
$(document).ready(function(){
$(".remove-link").click(function() {
$(this).parent(".number-row").hide();
})
})
</script>
Run Code Online (Sandbox Code Playgroud)
<div class="number-row" >
<div class="number-column">
<div class="label-row">
Select Country:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="label-row">
Select Toll Free or City:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="label-row">
Select Your Number:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
</div>
<div class="number-column">
<div class="label-row">
Select Country:
</div>
<div class="input-row">
<select>
<option>1</option>
<option>2</option>
</select>
</div>
<div class="label-row">
Enter Number to Forward to:
</div>
<div class="input-row"> …
Run Code Online (Sandbox Code Playgroud) 我希望我的Web应用程序用户将一些数据下载为Excel文件.
我有下一个函数在响应对象中发送输入流.
public static void sendFile(InputStream is, HttpServletResponse response) throws IOException {
BufferedInputStream in = null;
try {
int count;
byte[] buffer = new byte[BUFFER_SIZE];
in = new BufferedInputStream(is);
ServletOutputStream out = response.getOutputStream();
while(-1 != (count = in.read(buffer)))
out.write(buffer, 0, count);
out.flush();
} catch (IOException ioe) {
System.err.println("IOException in Download::sendFile");
ioe.printStackTrace();
} finally {
if (in != null) {
try { in.close();
} catch (IOException ioe) { ioe.printStackTrace(); }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想将我的HSSFWorkbook对象转换为输入流并将其传递给前一个方法.
public InputStream generateApplicationsExcel() {
HSSFWorkbook wb = …
Run Code Online (Sandbox Code Playgroud) String.length
只会告诉我String中有多少个字符.(事实上,在Ruby 1.9之前,它只会告诉我有多少字节,这些字节的用处更少.)
我真的希望能够找出一个字符串的'en'宽度.例如:
'foo'.width
# => 3
'moo'.width
# => 3.5 # m's, w's, etc. are wide
'foi'.width
# => 2.5 # i's, j's, etc. are narrow
'foo bar'.width
# => 6.25 # spaces are very narrow
Run Code Online (Sandbox Code Playgroud)
如果我能得到n
String 的第一个en,那就更好了:
'foo'[0, 2.en]
# => "fo"
'filial'[0, 3.en]
# => "fili"
'foo bar baz'[0, 4.5en]
# => "foo b"
Run Code Online (Sandbox Code Playgroud)
如果我可以策划整个事情,那就更好了.有些人认为空间应该是0.25en,有些人认为它应该是0.33等.
我在理解这里的问题时遇到了一些麻烦.我有一些代码使用LINQ从数据库中提取记录,并将它们放入一个被转换为接口的对象中.看起来有点像这样:
public IEnumerable<ISomeObject> query()
{
return from a in dc.SomeTable
select new SomeObject
{
//Assign various members here
} as ISomeObject;
}
Run Code Online (Sandbox Code Playgroud)
当我测试它时,我将返回的IEnumerable放入一个名为results的变量中并运行以下行:
Assert.AreEqual(EXPECTED_COUNT, results.Count());
Run Code Online (Sandbox Code Playgroud)
运行它时,我得到一个System.Security.VerificationException:"操作可能会破坏运行时的稳定性."
我在这里找到了解决方案,这是:
var results = from a in dc.SomeTable
select new SomeObject
{
//Assign various members here
} as ISomeTable;
return results.OfType<ISomeObject>();
Run Code Online (Sandbox Code Playgroud)
这有效,但我无法理解这里发生的事情.为什么我首先得到异常,上面的代码行是如何解决的?MSDN文档似乎表明这是类型安全的问题,但我没有看到以前的代码类型不安全的地方.
更新 我发现的更多信息.如果我返回类型IQueryable,第一个示例有效.这揭示了一点点光什么是走错了,但我仍然感到困惑的原因.为什么编译器不强迫我将IEnumerable转换为IQueryable?
我必须将一些groovy代码发送给一些只安装了java的用户(没有grooy,没有$ groovy_home等).我试图从命令行调用groovy,但我没有运气.这是我的bat文件:
java -classpath .;lib;bin;bin-groovy introspector.AclCollector
Run Code Online (Sandbox Code Playgroud)
这是我的例外:
Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 12 more
Could not find the main class: introspector.AclCollector. Program will exit.
Run Code Online (Sandbox Code Playgroud)
有人有线索吗?我在\ lib目录中有'groovy-all-1.6-beta-1.jar'.
我创建了一个 NamedTemporaryFile,在其中添加了一些内容,现在我想将它保存到模型 FileField 中。
问题是我得到了一个 SuspiciousOperation,因为 tmp 目录不在 FileSystemStorage 目录中。
这样做的正确方法是什么?
我需要知道Python中的变量是字符串还是字典.以下代码有什么问题吗?
if type(x) == type(str()):
do_something_with_a_string(x)
elif type(x) == type(dict()):
do_somethting_with_a_dict(x)
else:
raise ValueError
Run Code Online (Sandbox Code Playgroud)
更新:我接受了avisser的回答(但如果有人解释为什么isinstance
更喜欢,我会改变主意type(x) is
).
但由于nakedfanatic提醒我,这是经常清洁剂使用的字典(作为case语句)比如果/ elif的/其他系列.
让我详细说明我的用例.如果变量是一个字符串,我需要将它放在一个列表中.如果它是一个字典,我需要一个唯一值的列表.这是我想出的:
def value_list(x):
cases = {str: lambda t: [t],
dict: lambda t: list(set(t.values()))}
try:
return cases[type(x)](x)
except KeyError:
return None
Run Code Online (Sandbox Code Playgroud)
如果isinstance
是首选,你会怎么写这个value_list()
功能?
Emacs Lisp函数通常像这样开始:
(lambda () (interactive) ...
Run Code Online (Sandbox Code Playgroud)
"(互动)"有什么作用?
我的团队中有人发誓通过使用某种GVim功能手动进行代码折叠.
由于我正在使用另一个编辑器并且不需要折叠功能,我认为它只会使用以下标签污染源代码:
/* {{{1 */
Run Code Online (Sandbox Code Playgroud)
说服该人不使用这种折叠不是一种选择(之前进行了一些激烈的讨论).
我不是一个真正的GVim家伙,我想知道在没有改变团队代码的情况下是否没有其他方法可以进行折叠?
java ×2
.net ×1
.net-3.5 ×1
apache-poi ×1
c ×1
c# ×1
c++ ×1
command-line ×1
django ×1
dom ×1
emacs ×1
file ×1
groovy ×1
include ×1
jquery ×1
linq ×1
linq-to-sql ×1
lisp ×1
model ×1
namespaces ×1
python ×1
ruby ×1
typechecking ×1
types ×1
typography ×1
upload ×1
vi ×1
vim ×1