我遇到了与上一个问题相同的问题: 在C++中使用未声明的标识符和模板以及继承
总结一下,我们尝试从子类访问模板类的protected属性.所描述的方法是使用this->attribute
而不是仅使用attribute
.问题是,我想知道为什么visual studio 2012不需要在程序的变量引用前添加this->来正确编译和执行.我还想知道是否有办法在OS X上的gcc或其他编译器中使用该功能.
编辑:这是我用于在visual studio 2012中测试的代码.
//file a.h
template<class T>
class a
{
public:
a(){value = 2;};
protected:
T value;
};
template<class T>
class b: public a<T>
{
public:
T getValue(){return value;};
};
//file main.cpp
#include <iostream>
#include "a.h"
using namespace std;
int main()
{
b<int> myTest;
cout<<myTest.getValue();
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这不是使用g ++编译,而是使用visual studio 2012.
我探索了一些解决方案,但没有取得太大成功。我有两个 python 进程(使用子进程中的 Popen 创建)和一个 mysql 表(称为persone
),其中包含一行两列:Age:0, id:1
。一个进程选择该行,获取它的年龄并将其加一。这样做了 1000 次。第二个做同样的事情,但是减少它。我并行运行每个进程。
理论上,我希望最后年龄保持为零。问题是我在 mymain.py 末尾不断获得 100 到 -100 之间的随机值,我猜这意味着同时进行了访问,从而损坏了数据库。我想知道我错过了什么?
这是我用来测试这个的代码:
ajoutAge.py
import MySQLdb as lite
num=1000
connexion = lite.connect(host="localhost", user="root", passwd="123", db="test")
with connexion:
for i in range(num):
cur = connexion.cursor()
cur.execute('start transaction')
cur.execute('select Age from persone where id=1')
age = cur.fetchone()[0]
cur.execute('update persone set Age='+str(age+1)+' where id=1')
# cur.execute('rollback')
cur.execute('commit')
print "ajout Done"
Run Code Online (Sandbox Code Playgroud)
RetraitAge.py
import MySQLdb as lite
num=1000
connexion = lite.connect(host="localhost", user="root", passwd="123", db="test")
with connexion: …
Run Code Online (Sandbox Code Playgroud) 当前正在研究各种浏览器的indexeddb限制。发现Chrome浏览器没有硬限制,但需要授予权限(Source),Firefox是本地存储的50%(Source),但是找不到Edge或Safari的任何内容。
我对Edge进行了实验,发现它没有IE设置的限制:每个域500MB(来源)
不幸的是navigator.storage.estimate()
在Edge https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/estimate上不起作用
是否有人对此有使用Edge或Safari的经验?
这将是两个问题之一
我有两段代码,唯一的区别是int*a声明之间的顺序; 和int cpt = 0; 在第6和第7行.
情况1:
#include <iostream>
using namespace std;
int main()
{
cout<<"begin"<<endl;
int* a;
int cpt = 0;
cout<<"after init "<<a<<endl;
*a = 2;
cout<<"after assign"<<endl;
cout<<a<<" "<<*a<<endl;
cout<<"after cout"<<endl;
int* b;
*b = 2;
cout<<b<<" "<<*b<<endl;
}
Run Code Online (Sandbox Code Playgroud)
输出:
begin
after init 0x7fff6c97f05e
Bus error: 10
Run Code Online (Sandbox Code Playgroud)
案例2:
#include <iostream>
using namespace std;
int main()
{
cout<<"begin"<<endl;
int cpt = 0;
int* a;
cout<<"after init "<<a<<endl;
*a = 2;
cout<<"after assign"<<endl;
cout<<a<<" "<<*a<<endl;
cout<<"after cout"<<endl;
int* …
Run Code Online (Sandbox Code Playgroud) c++ ×2
bus-error ×1
compilation ×1
concurrency ×1
gcc ×1
indexeddb ×1
javascript ×1
macos ×1
mysql ×1
pointers ×1
process ×1
python ×1
safari ×1