我在以下链接中找到了官方的"Java编程语言增强功能".
http://download.oracle.com/javase/7/docs/technotes/guides/language/enhancements.html#javase7
有谁知道Java 7的官方语法文件?
我要做的是了解Java 6和Java 7之间的区别并增强我的解析器.
先感谢您
我基于这个概念问了这个函数(可能不正确?!):只要const存在,就可以在这个地方存在一个volatile.
class classA
{
public:
const int Foo() const;
}
Run Code Online (Sandbox Code Playgroud)
这里第一个"const"表示返回值是const,我们无法改变它.第二个const表示"Is Query",这个函数不能改变成员变量而不能调用非const函数.
现在变得不稳定:我可以理解volatile对变量的作用,比如"volatile int a".但是我不知道以下几点之间的区别:
Case 1: The return type is volatile?
volatile void Function1();
Case 2: The function can only call volatile functions? Why add volatile here? Any example?
void Function2() volatile;
Case 3: Is it valid? If yes, is it simply a combination of Case 1 and Case 2?
volatile void Function3() volatile;
Run Code Online (Sandbox Code Playgroud)
当我们将const放在函数声明的末尾时,它有一个漂亮的名字:"Is Query"你能为Case 2中的"volatile"提供一个合适的名字/别名吗?我的意思是,每当我们称这个名字时,我们都知道我们在谈论案例2,而不是案例1.
先感谢您!
假设我已经安装了多个版本的软件,一些DLL被注册为COM.例如:
.../version1/Application.exe
normal.dll
comObject.dll -- register as COM to use
.../version2/Application.exe
normal.dll
comObject.dll -- register as COM to use
Run Code Online (Sandbox Code Playgroud)
怎么知道哪个comObject.dll已注册?(哪个路径?在文件夹"version1"或"version2"下?) 答:这样做的一种方法是使用"Process Explorer",转到"Find | Find Handle or DLL ... ",输入"comObject.dll"然后单击"搜索"按钮. 然后路径显示在列表中.
现在谈谈我的问题:如果一个软件包很庞大,安装了数百个基于COM的DLL,我不想手动打开"Peocess Explorer"并在搜索结果中搜索每个DLL/OCX/EXE,我不可能将列表内容复制出来!!
我想要的只是一个像下面的命令一样运行的工具,我可以在一个bat文件中运行.
ProcessExplorer.exe -Find "comObject1.dll" -append "C:\temp\output.txt"
ProcessExplorer.exe -Find "comObject2.dll" -append "C:\temp\output.txt"
ProcessExplorer.exe -Find "comObject3.dll" -append "C:\temp\output.txt"
Run Code Online (Sandbox Code Playgroud)
output.txt可能如下所示:
Process PID Type Handle or DLL
comObject1.dll 1 DLL C:\ApplicationExample\Version1\comObject1.dll
comObject2.dll 1 DLL C:\ApplicationExample\Version1\comObject2.dll
comObject3.dll 1 DLL C:\ApplicationExample\Version2\comObject3.dll
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,comObject1.dll和comObject2.dll来自Version1文件夹,而comObject3.dll来自Version2文件夹.
有了代码,我有以下输出:
A::A() is called
test #1
A::A(const A & other) is called
test #2
A::A(const A & other) is called
A::A(const A & other) is called
test #3
A::A(const A & other) is called
A::A(const A & other) is called
A::A(const A & other) is called
Run Code Online (Sandbox Code Playgroud)
在调试代码时,对于3个测试用例,我发现第一次复制构造函数的调用是相同的(我认为这是有意义的):制作对象的副本并推送到向量.
但是,通过"_Umove_if_noexcept"对复制构造函数进行额外调用.
对于测试#2,当vec已经有一个条目时,它将进一步调用复制构造函数的一次.
对于测试#3,当vec已经有两个条目时,它将进一步调用复制构造函数的两倍.
这在Visual Studio 2017和gcc 5.4.0上是可重现的.
为什么会这样?是否存在性能问题?
谢谢
#include <iostream>
#include <vector>
class A
{
public:
//constructor
A()
{
a = 10;
std::cout << "A::A() is called" << std::endl;
}
//copy constructor …Run Code Online (Sandbox Code Playgroud) 我刚读过"Ada Programming",但我对如何'在Ada中使用(单引号)感到困惑.
我可以理解,'它用于引用属性.AAA'Image(..),BBB'Value(..)
但是,考虑到这段代码:
type Plain_Vector (Capacity : Capacity_Subtype) is record
Elements : Elements_Array (1 .. Capacity);
Last : Extended_Index := No_Index;
Busy : Natural := 0;
Lock : Natural := 0;
end record;
------------------------------------------------------------------
new Plain_Vector'(2, (Left, Right), Last => Last, others => <>)
Run Code Online (Sandbox Code Playgroud)
Q1: "new"语句的参数如何与类型的参数和记录字段匹配?
I can GUESS "2" matched "Capacity",
"(Left, Right)" matched "Elements",
"Last => Last" matched "Last"
"Others => <>" matched "Busy" and "Lock" to let them use default …Run Code Online (Sandbox Code Playgroud) 我正在Yosemite的XCode上运行.
代码编译但在运行时崩溃,为什么?
我故意在第二个std :: copy中使用"{}"作为"范围结束".
我试验了这段代码,因为一个工作示例使用"{}"作为"默认构造的流迭代器作为范围的结尾".
那么为什么(见第二个代码)一个正在工作,但这个(第一个代码)一个失败了?
#include <algorithm>
#include <iterator>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<int> coll1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// copy the elements of coll1 into coll2 by appending them
vector<int> coll2;
copy (coll1.cbegin(), coll1.cend(), // source
back_inserter(coll2)); // destination
vector<int> coll3;
copy (coll1.begin(), {},
back_inserter(coll3));
}
Run Code Online (Sandbox Code Playgroud)
以下代码来自The C++ Standard Library第二版.
带有"// end of source"的行可以是"istream_iterator()",也可以是"{}",
两者都有效,因为:引用了这本书
"请注意,从C++ 11开始,您可以将空的花括号而不是默认构造的流迭代器作为范围的结尾传递.这是有效的,因为定义源范围结束的参数类型是从前一个参数推导出来的它定义了源范围的开始."
/* The following code example is …Run Code Online (Sandbox Code Playgroud) 在问题之前:我理解std::map::lower_bound和std::map::upper_bound的含义
问题:如何获得一个指向不大于 key 的最后一个元素的迭代器。
以下示例显示了 lower_bound/upper_bound 的当前行为。
但是,我想要:
我怎样才能实现这个目标?
#include <iostream>
#include <map>
int main ()
{
std::map<int,char> mymap;
std::map<int,char>::iterator itlow,itup;
mymap[10]='a';
mymap[20]='b';
mymap[30]='c';
mymap[40]='d';
mymap[50]='e';
itlow=mymap.lower_bound (20); // itlow points to 'b'
std::cout << "lower_bound for 20: " << itlow->first << " => " << itlow->second << '\n';
itup=mymap.upper_bound (20); // itup points to 'c'
std::cout << "upper_bound for 20: " << itup->first << " => " << itup->second << '\n';
itlow=mymap.lower_bound (25); // …Run Code Online (Sandbox Code Playgroud) 我编写了一段时间的C++.现在我想编写ANSI C程序,不希望代码中有任何"仅C++"功能.我正在使用安装了gcc的cygwin 64位.如果遇到C++功能,是否有任何设置让gcc提示编译错误?比如stl.
先感谢您.
什么是迭代两个列表和计算的Pythonic方法?
a, b=[1,2,3], [4,5,6]
c=[]
for i in range(3):
c.append(a[i]+b[i])
print(c)
[5,7,9]
Run Code Online (Sandbox Code Playgroud)
c没有for循环是否有单线程?
我知道隐式复制构造函数/赋值运算符对源对象进行成员明智的复制。
假设我的班级有 1000 名成员。我想在进行赋值赋值时抑制其中一个成员(并且应用默认值),其他 999 个成员仍然使用成员明智的复制作为隐式赋值运算符。
例如:
class Foo
{
std::string s1;
std::string s2;
std::string s3;
....
std::string s1000;
};
Run Code Online (Sandbox Code Playgroud)
然后我们用一些值填充对象 f1:
Foo f1;
f1.s1 = "a";
f1.s2 = "b";
f1.s3 = "c";
...
Run Code Online (Sandbox Code Playgroud)
现在我们复制将 f1(源)分配给 f2(目标)
Foo f2 = f1;
Run Code Online (Sandbox Code Playgroud)
如果我想抑制“s2”,如何才能达到以下结果?
assert(f2.s1 == "a");
assert(f2.s2 == ""); //default value
assert(f2.s3 == "c");
Run Code Online (Sandbox Code Playgroud)
我知道提供复制构造函数/赋值运算符将解决这个问题。
class Foo
{
Foo( const Foo& other)
{
s1 = other.s1;
//s2 = other.s2; //suppress s2
s3 = other.s3;
...
s1000 = other.s1000;
};
Foo& Foo::operator=( …Run Code Online (Sandbox Code Playgroud) 我对 Java 很满意
ArrayList<String> list = new ArrayList<>();
Iterator<SignalEvent> it = list.iterator();
while (it.hasNext()) {
String s = it.next();
if(s.equals("delete me")){
it.remove();
}
}
Run Code Online (Sandbox Code Playgroud)
不太高兴,但对 C++ 感觉还可以
std::list<MyObject*> mylist;
for (list<MyObject*>::iterator it = mylist.begin(); it != mylist.end();)
{
MyObject* se = (*it);
if(se->bDelete == true)
it = mylist.erase(it);
else
it++;
}
Run Code Online (Sandbox Code Playgroud)
现在谈到 C#,这是最好的方法吗?
你有迭代器的方式吗?
考虑到性能和可读性,您有更好的建议吗?
for( int i = arrayList.Count - 1; i >= 0; i -- )
{
if( arrayList[ i ].ToString() == "del" )
{
arrayList.RemoveAt( i ); …Run Code Online (Sandbox Code Playgroud) 我通过在开始时设置断点来调试Visual Studio 2008(64位)中的以下代码,do_test1并且do_test2令我惊讶的是,代码在sc_main函数的同一个线程中运行.
我没有在Linux环境中调试.但是,通过搜索源代码,我发现"pthread.h"一些SystemC库源代码包含了它.
问题1:在Windows中,是否会SC_THREAD创建一个真正的线程?或者它总是在同一个线程中sc_main?如果是这种情况,我可以说SC_THREAD是创建一个"假"线程吗?
问题2:在Linux中,既然"pthread.h"包括在内,会SC_THREAD创建一个新的线程吗?
问题3:在Windows和Linux中,我是否错过了启用真实线程的一些设置?
========================================
以下代码来自本网站:
http://www.asic-world.com/systemc/systemc_time4.html#Example_:_sc_event
#include <systemc.h>
SC_MODULE (events) {
sc_in<bool> clock;
sc_event e1;
sc_event e2;
void do_test1() {
while (true) {
// Wait for posedge of clock
wait();
cout << "@" << sc_time_stamp() <<" Starting test"<<endl;
// Wait for posedge of clock
wait();
cout << "@" << sc_time_stamp() <<" Triggering e1"<<endl;
// Trigger event e1
e1.notify(5,SC_NS); …Run Code Online (Sandbox Code Playgroud)