我想编写应该使用的泛型类byte
和ushort
类型.我应该为这门课使用什么约束?如何检测MaxValue
此类内部的属性?
class MyClass<T> // where T: ???
{
void Foo()
{
int maxValue = T.MaxValue; // how can I do this?
}
}
Run Code Online (Sandbox Code Playgroud)
如果类是使用意外类型创建的,它不包含MaxValue属性,我不在乎 - 例如,我可以在运行时抛出异常.
在Unix/Linux中保留用户配置数据的推荐方法是什么?我的编程语言是C++.配置数据将以XML /文本/二进制格式保存,我对处理此类文件没有任何问题.我想知道我在哪里可以保留它们.例如,在Windows OS配置中,数据可以保存在Registry(旧方式)或用户应用程序数据目录中.Linux怎么样?我需要对配置文件的读/写访问权限.
我有以下XML文件:
<xml version="1.0" encoding="utf-8"?> <Data> <Parameter1>1</Parameter1> </Data>
我想在Data节点中添加一个新节点:Parameter2 ="2".此代码不起作用,保存的文件仍然只包含一个参数:
boost::property_tree::ptree tree; boost::property_tree::ptree dataTree; read_xml("test.xml", tree); dataTree = tree.get_child("Data"); dataTree.put("Parameter2", "2"); boost::property_tree::xml_writer_settings w(' ', 4); write_xml("test.xml", tree, std::locale(), w);
如果我在dataTree.put之后添加这两行,我得到正确的结果:
tree.clear(); tree.add_child("Data", dataTree);
我不喜欢这个解决方案,因为它会产生更复杂的树结构问题.是否可以在不删除/添加子节点的情况下更新属性树?
此描述适用于Linux 32位:当Linux程序开始时,所有指向命令行参数的指针都存储在堆栈中.参数的数量存储在0(%ebp),程序的名称存储在4(%ebp),参数存储在8(%ebp).
64位需要相同的信息.
编辑:我有工作代码示例,演示如何使用argc,argv [0]和argv [1]:http://cubbi.com/fibonacci/asm.html
.globl _start _start: popq %rcx # this is argc, must be 2 for one argument cmpq $2,%rcx jne usage_exit addq $8,%rsp # skip argv[0] popq %rsi # get argv[1] call ... ... }
看起来参数在堆栈上.由于此代码不清楚,我问这个问题.我猜我可以将rp保留在rbp中,然后使用0(%rbp),8(%rbp),16(%rbp)等来访问这些参数.这是正确的吗?
Cppcheck为scanf显示以下警告:
Message: scanf without field width limits can crash with huge input data. To fix this error message add a field width specifier: %s => %20s %i => %3i Sample program that can crash: #include int main() { int a; scanf("%i", &a); return 0; } To make it crash: perl -e 'print "5"x2100000' | ./a.out
我无法崩溃这个程序输入"巨大的输入数据".我应该输入什么才能让这次崩溃?我也不明白这个警告中最后一行的含义:
perl -e ...
码:
#include <iostream>
#include <thread>
void hello()
{
std::cout << "Hello World" << std::endl;
}
int main()
{
try
{
std::cout << "creating thread" << std::endl;
std::thread t(hello);
std::cout << "waiting" << std::endl;
t.join();
std::cout << "done" << std::endl;
}
catch(std::exception& ex)
{
std::cout << ex.what() << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
建立:
g++ -Wall -fexceptions -std=c++0x -pthread -g -c /home/alex/tmp/thread_test/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/thread_test obj/Debug/main.o
Output size is 106.62 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 …
Run Code Online (Sandbox Code Playgroud) 在Windows应用商店应用中,我可以使用:
System.Diagnostics.Debug.WriteLine("Test");
Run Code Online (Sandbox Code Playgroud)
但更换Debug
同Trace
提供了以下错误:CS0103: The name 'Trace' does not exist in the current context
我怎样才能解决这个问题?
我按照本页的说明安装了wxWidgets-2.8.10:http://wiki.wxwidgets.org/Compiling_and_getting_started
库目录:
alex@alex-linux:/usr/local/lib$ ls | grep wx libwx_base-2.8.a libwx_base_net-2.8.a libwx_base_xml-2.8.a libwx_gtk2_adv-2.8.a libwx_gtk2_aui-2.8.a libwx_gtk2_core-2.8.a libwx_gtk2_html-2.8.a libwx_gtk2_qa-2.8.a libwx_gtk2_richtext-2.8.a libwx_gtk2_xrc-2.8.a libwxtiff-2.8.a wx
然后我创建了文件widgetTest.cpp并用以下代码填充它:http://www.wxwidgets.org/docs/tutorials/hworld.txt
试图构建它,我有很多链接器错误:
alex@alex-linux:~$ cd /home/alex/Tmp alex@alex-linux:~/Tmp$ g++ `wx-config --cppflags` `wx-config --libs` widgetTest.cpp /tmp/ccnPCAw5.o: In function `wxCreateApp()': widgetTest.cpp:(.text+0x2d): undefined reference to `wxAppConsole::CheckBuildOptions(char const*, char const*)' /tmp/ccnPCAw5.o: In function `main': ... widgetTest.cpp:(.text._ZN20wxThreadHelperThreadD0Ev[wxThreadHelperThread::~wxThreadHelperThread()]+0x16): undefined reference to `wxThread::~wxThread()' collect2: ld returned 1 exit status
附加信息:
alex@alex-linux:~$ wx-config --cppflags -I/usr/local/lib/wx/include/gtk2-ansi-release-static-2.8 -I/usr/local/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ alex@alex-linux:~$ wx-config --libs -L/usr/local/lib -pthread /usr/local/lib/libwx_gtk2_richtext-2.8.a /usr/local/lib/libwx_gtk2_aui-2.8.a /usr/local/lib/libwx_gtk2_xrc-2.8.a …
我试图通过虚拟COM端口与硬件设备通信.主机是PC Windows OS PC.设备正在使用921600波特率.此代码有效:
DCB dcb; ... dcb.BaudRate = CBR_115200; SetCommState(hPort, &dcb);
一旦我改变波特率:
dcb.BaudRate = 921600;
SetCommState失败,出现上一个错误0x57
(参数不正确).这是否意味着Windows API会阻止除预定义值之外的任何波特率?或者,虚拟COM端口可能配置为允许此波特率?
虚拟COM端口是CameraLink连接的一部分.我正在与CameraLink板卡供应商交谈.但我需要知道Windows串行通信API是否支持自定义波特率.
在VS2012 C#文本编辑器中,当在/* */
注释中按Enter键时,将添加新行,从*
.是否可以禁用此行为并获得一个空的新行?
从Visual Studio关于框,已安装的产品:
Microsoft Visual Studio Professional 2012 Microsoft Team Explorer for Visual Studio 2012 Microsoft Visual Basic 2012 Microsoft Visual C# 2012 Microsoft Visual C++ 2012 Microsoft Visual F# 2012 Microsoft® Visual Studio® 2012 Code Analysis Spell Checker NuGet Package Manager PreEmptive Analytics Visualizer