假设我有一个类的对象,如下所示:
Myclass obj;
现在我想将此对象存储到我想要的内存位置。我怎样才能做到这一点?有没有可能?
我创建了一个数组类,它只是在相应的索引中插入整数类型的数据,但数组的大小未在类中声明。我插入了 50 到 60 个整数之类的少量数据,然后我使用循环在这个类中插入了一个大数据,但是这次我的程序崩溃了,我认为是因为如果在内存中遇到一些索引,它有一些值,程序自行停止。现在我想分析我的数组类对象从包含最大可用空可用内存空间的特定地址开始的内存
我认为由于分配了一些内存位置,它不允许更多的插入。现在我想将我的对象放在包含最大可用空可用空间的内存地址上。请指导我
#include<iostream>
using namespace std;
class newarray
{
public:
int n;
int arr[]; //size not declared
int* ptr;
newarray():n(0),ptr(NULL)
{
}
void getadress(int indexno) //for getting address of an index
{
ptr=&arr[indexno];
cout<<endl<<ptr;
}
void insert(int a) //inserting an element
{
arr[n]=a;
n++;
}
void display()
{
for(int i=0;i<=n;i++)
{
cout<<endl<<arr[i];
}
}
};
int main()
{
newarray a1;
int x=1;
for(int i=0;i<100;i++) //work good with 100 inssertions
//but if exceed to 300 or more it crashes.
{
a1.insert(x);
x++;
}
a1.display();
}