该消息warning CS8604: Possible null reference argument是在呼叫 时发出的Process()。修复方法是将其标记为MemberNotNull。
如果 Derived 类中没有重写,则 MemberNotNull 按预期工作。
如果存在覆盖,为什么编译器仍然会发出警告?
有什么更好的方法来抑制这个警告?
using System;
using System.Diagnostics.CodeAnalysis;
namespace Tests
{
class Base
{
public virtual string? Member { get; set; }
[MemberNotNull(nameof(Member))]
public void Validate()
{
if (Member is null)
{
throw new Exception("Prop is null");
}
}
}
class Derived : Base
{
public override string? Member { get; set; } // warning CS8604: Possible null reference argument
}
[TestClass]
public class …Run Code Online (Sandbox Code Playgroud) 我正在使用这段代码来显示网站上的用户数量.我的客户抱怨它看起来很假.有什么建议?
var visitors = 187584;
var updateVisitors = function()
{
visitors++;
var vs = visitors.toString(),
i = Math.floor(vs.length / 3),
l = vs.length % 3;
while (i-->0) if (!(l==0&&i==0))
vs = vs.slice(0,i*3+l)
+ ','
+ vs.slice(i*3+l);
$('#count').text(vs);
setTimeout(updateVisitors, Math.random()*2000);
};
setTimeout(updateVisitors, Math.random()*2000);
Run Code Online (Sandbox Code Playgroud)
编辑:
alt text http://img695.imageshack.us/img695/4268/reachdevs2.png 截图 - 广告 - Stack Overflow - Chromium http://img130.imageshack.us/img130/8083/screenshotadvertisestac.png
我们在Ubuntu/Mac上开发并将RPM部署到CentOS(这是设置,不能改变太多).
问题是当从rpm安装时,包转到/usr/local/lib/python2.7/dist-packages(这是Ubuntu的正确位置).但是,CentOS中的默认python路径正在查看/usr/local/lib/python2.7/site-packages.
有没有办法告诉bdist_rpm在哪里安装文件?
我看到了这段代码,但我无法理解它的作用:
inline S* O::operator->() const
{
return ses; //ses is a private member of Type S*
}
Run Code Online (Sandbox Code Playgroud)
那么如果我用的话会发生什么->?
当我使用isql进行查询时,我得到以下消息和查询块.
数据库foo中的事务日志几乎已满.您的事务将暂停,直到日志中的空间可用.
当我从Python做同样的事情时:
cursor.execute(sql)
Run Code Online (Sandbox Code Playgroud)
查询阻止,但我想看到此消息.
我试过了:
Sybase.set_debug(sys.stderr)
connection.debug = 1
Run Code Online (Sandbox Code Playgroud)
我正在使用:
编辑:问题是,"如何在python程序中捕获此警告消息?"
我正在使用这个is_enum函数来检查变量是否是枚举.(见下面的错误)
#include <boost/type_traits/is_enum.hpp>
#include <boost/static_assert.hpp>
template<typename T>
void is_enum(T)
{
BOOST_STATIC_ASSERT(boost::is_enum<T>::value == true);
}
int main()
{
char c = 'a';
is_enum(c);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:
-*- mode: compilation; default-directory: "/home/epronk/enums/" -*-
Compilation started at Thu Nov 10 21:20:05
g++ -I /home/epronk/src/boost_1_47_0/ q.cpp
q.cpp: In function ‘void is_enum(T) [with T = char]’:
q.cpp:13: instantiated from here
q.cpp:7: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’
q.cpp:7: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’
Compilation exited abnormally with …Run Code Online (Sandbox Code Playgroud) 我在代码中发现了一个错误,我将指针与'\ 0'进行了比较.
想知道为什么编译器没有警告我这个bug我试过以下.
#include <cassert>
struct Foo
{
char bar[5];
};
int main()
{
Foo f;
Foo* p = &f;
p->bar[0] = '\0';
assert(p->bar == '\0'); // #1. I forgot [] Now, comparing pointer with NULL and fails.
assert(p->bar == 'A'); // #2. error: ISO C++ forbids comparison between pointer and integer
assert(p->bar[0] == '\0'); // #3. What I intended, PASSES
return 0;
}
Run Code Online (Sandbox Code Playgroud)
'\ 0'有什么特别之处,它使#1合法,#2非法?
请在答案中添加引用或引用.
我正在尝试与NCURSES计划进行互动.
作为一个例子,我使用GNU Screen并在内部运行aptitude.(你可以用mc来试试.)
下面的程序使用-x启动屏幕会话以连接到我的会话.
我想通过按向下箭头和向上箭头来导航.
如果我发送'q'退出,我会在其他屏幕会话中弹出一个框.
我需要做什么才能获得箭头键等特殊键?
它目前似乎忽略了我发送的VT102序列.
from twisted.internet import protocol, reactor
class MyPP(protocol.ProcessProtocol):
def connectionMade(self):
reactor.callLater(1.0, self.foo)
def foo(self):
self.transport.write('\033[B')
def processExited(self, reason):
print "processExited, status %s" % (reason.value.exitCode,)
def outReceived(self, data):
print data
def errReceived(self, data):
print "errReceived!", data
pp = MyPP()
command = ['screen', '-x']
reactor.spawnProcess(pp, command[0], command, {'TERM':'xterm'}, usePTY=True)
reactor.run()
Run Code Online (Sandbox Code Playgroud)
更新:
泰德告诉我,走在与ESC [A(上)和ESC [B(下)使用bash工作的命令历史记录.
奇怪,为什么性向不我已经改变TERM = xterm中以TERM = ANSI其修复它.为什么xterm不起作用仍困扰着我.
根据这篇文章,谷歌C++测试框架认为"make install"是一种不好的做法.
http://groups.google.com/group/googletestframework/browse_thread/thread/668eff1cebf5309d
原因是该库违反了"一个定义规则".
http://en.wikipedia.org/wiki/One_Definition_Rule
它在线程中的某个地方说:"如果你将不同的-DGTEST_HAS_FOO = 1标志传递给不同的翻译单元,你将违反ODR.或者有时人们使用-D来选择使用哪个malloc库(调试与发布),以及你必须全面使用相同的malloc库."
我的问题:
我需要依赖项,因为我想将这些添加到我的 RPM 元数据中。
要构建我使用:
python setup.py bdist_rpm
Run Code Online (Sandbox Code Playgroud)
当我构建包时,cryptography-2.2.2它会创建一个文件/src/cryptography.egg-info/requires.txt
它包含了:
idna>=2.1
asn1crypto>=0.21.0
six>=1.4.1
[:platform_python_implementation != 'PyPy']
cffi>=1.7
[:python_version < '3']
enum34
ipaddress
Run Code Online (Sandbox Code Playgroud)
如何读取所有依赖项,评估 之间的表达式[]?
我正在使用 Python 2.7(不要问)
我需要以下输出:
idna>=2.1
asn1crypto>=0.21.0
six>=1.4.1
cffi>=1.7
enum34
ipaddress
Run Code Online (Sandbox Code Playgroud)
我想省略其他部分,如[doc],[test]等等。
c++ ×4
python ×4
c# ×1
centos ×1
googletest ×1
javascript ×1
rpm ×1
sybase-ase ×1
twisted ×1
ubuntu ×1