
#include<string>
using namespace std
class Employee{
private:
string name
string address
string city
string postcode
public:
Employee():name("a"),address("b"),city("c"),postcode("d"){}
Employee(string n,string a,string c,string p):name(n),address(a),city(c),postcode(p){
cout<<"End Entering"<<endl}
~Employee(){cout<<"End"<<endl}
void setName(){
string n
cout<<"Enter Nmae:"
cin>>n
name=n}
void display(){
cout<<"Name:"<<name<<endl
cout<<"Address:"<<address<<endl
cout<<"City:"<<city<<endl
cout<<"Postcode:"<<postcode<<endl
cout<<"Displaying all"<<endl}
}
int main(){
Employee * p=new Employee[2]
p[0].display()
cout<<endl
p[1].display()
delete[] p //错误,这是一个数组要加[]
cout<<endl
p=new Employee("e","r","t","y") //现在的p不是数组了,那下面这样都是错误的
p->display() //这里p是一个指向对象的指针
cout<<endl
//p[1].display()
delete p
return 0
}
你的DLL必须是COM组件才能通过这种方式添加引用,如果不是就不行。但是,如果不是COM组件,有另外一种方式使用dll,就是import里面的函数,需要做个包装类,在里面把dll中的方法包装一下,具体的可以网上搜搜C# import dll用法。
C语言:申请:DataType *p = (DataType*)malloc(sizeof(DataType) * n)
释放:free(p)
C++:
申请:DataType *p = new DataType[n]
释放:delete[] p
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)