#include <iostream>
#include <conio.h>
using namespace std;
int i1 = 0;
class Test
{
int _id;
public:
Test(int id = i1++):_id(id)
{
cout << "Create Object: " << this << " _id: " << _id << endl;
}
~Test()
{
cout << "Delete Object: " << this << " _id: " << _id << endl;
if(i1) i1--;
}
void ShowID()
{
cout << "ShowID() " << this << " _id: " << _id << endl;
}
};
int main()
{
long int num;
cin >> num;
cout << endl;
Test *obj= new Test[num];
for(int i=0; i < num; ++i)
{
obj[i].ShowID();
}
delete[] obj;
_getch();
return 0;
}
БЕЗ материала для новичков
#include <QObject>
#include <QVector>
class Foo: public QObject
{
Q_OBJECT
Q_PROPERTY(QVector<bool> b READ getData WRITE setData)
public:
Foo()
{
m_b.resize(30);
for(auto &b:m_b)
{
b = true;
}
}
QVector<bool> getData()
{
return m_b;
}
void inv()
{
for(auto &b:m_b)
{
b = !b;
}
}
void setData(QVector<bool> b)
{
m_b = b;
}
private:
QVector<bool> m_b;
};
class Bar: public QObject
{
Q_OBJECT
Q_PROPERTY(QVector<bool> b WRITE setData)
public:
Bar(){};
void printData()
{
for(auto &b:m_b)
{
qDebug() << b << ' ';
}
}
void setData(QVector<bool> b)
{
m_b = b;
}
private:
QVector<bool> m_b;
};
int main(int argc, char *argv[])
{
Foo foo;
Bar bar;
bar.setData(foo.getData());
bar.printData();
qDebug() << "modify\n";
foo.inv();
bar.setProperty("b", foo.property("b"));
bar.printData();
}
package primary.utils
{
import flash.utils.ByteArray;
public class IiiEncryptionXor
{
public function IiiEncryptionXor()
{
super();
}
public static function encrypt(string:String, key:String) : String
{
var barr:ByteArray = new ByteArray();
barr.writeUTFBytes(Base64.encode(string));
var xstr:String = xorr(barr,key);
return Base64.encode(xstr);
}
public static function decrypt(string:String, key:String) : String
{
var barr:ByteArray = Base64.decodeToByteArray(string);
var xstr:String = xorr(barr,key);
return Base64.decode(xstr);
}
private static function xorr(barr:ByteArray, key:String) : String
{
var keypos:Number = NaN;
var keyByteArr:ByteArray = new ByteArray();
keyByteArr.writeUTFBytes(key);
var keylen:int = keyByteArr.length;
var barrlen:int = barr.length;
var barrNew:ByteArray = new ByteArray();
for(var i:int = 0; i < barrlen; i++)
{
keypos = i % keylen;
barrNew[i] = barr[i] ^ keyByteArr[keypos];
}
return barrNew.toString();
}
}
}
private const VERY_LONG:String = "some very-very long string without any non-latin characters due to different string representations inside of variable programming languages";
package primary.utils
{
import flash.utils.ByteArray;
public class Base64
{
private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
public static const version:String = "1.1.0";
public function Base64()
{
super();
throw new Error("Base64 class is static container only");
}
public static function encode(data:String) : String
{
var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(data);
return encodeByteArray(bytes);
}
public static function encodeByteArray(data:ByteArray) : String
{
var dataBuffer:Array = null;
var i:uint = 0;
var j:uint = 0;
var k:uint = 0;
var output:String = "";
var outputBuffer:Array = new Array(4);
data.position = 0;
while(data.bytesAvailable > 0)
{
dataBuffer = new Array();
i = 0;
while(i < 3 && data.bytesAvailable > 0)
{
dataBuffer[i] = data.readUnsignedByte();
i++;
}
outputBuffer[0] = (dataBuffer[0] & 252) >> 2;
outputBuffer[1] = (dataBuffer[0] & 3) << 4 | dataBuffer[1] >> 4;
outputBuffer[2] = (dataBuffer[1] & 15) << 2 | dataBuffer[2] >> 6;
outputBuffer[3] = dataBuffer[2] & 63;
for(j = dataBuffer.length; j < 3; j++)
{
outputBuffer[j + 1] = 64;
}
for(k = 0; k < outputBuffer.length; k++)
{
output = output + BASE64_CHARS.charAt(outputBuffer[k]);
}
}
return output;
}
public static function decode(data:String) : String
{
var bytes:ByteArray = decodeToByteArray(data);
return bytes.readUTFBytes(bytes.length);
}
public static function decodeToByteArray(data:String) : ByteArray
{
var j:uint = 0;
var k:uint = 0;
var output:ByteArray = new ByteArray();
var dataBuffer:Array = new Array(4);
var outputBuffer:Array = new Array(3);
for(var i:uint = 0; i < data.length; i = i + 4)
{
j = 0;
while(j < 4 && i + j < data.length)
{
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));
while(dataBuffer[j] < 0 && i < data.length)
{
i++;
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));
}
j++;
}
outputBuffer[0] = (dataBuffer[0] << 2) + ((dataBuffer[1] & 48) >> 4);
outputBuffer[1] = ((dataBuffer[1] & 15) << 4) + ((dataBuffer[2] & 60) >> 2);
outputBuffer[2] = ((dataBuffer[2] & 3) << 6) + dataBuffer[3];
for(k = 0; k < outputBuffer.length; k++)
{
if(dataBuffer[k + 1] == 64)
{
break;
}
output.writeByte(outputBuffer[k]);
}
}
output.position = 0;
return output;
}
}
}