#pragma once
class ArrayOne {
public:
friend ArrayOne operator +=(const ArrayOne &a, const ArrayOne &d);
ArrayOne(const int init);
ArrayOne();
~ArrayOne();
void show();
ArrayOne operator+(const ArrayOne &arrayOne)const;
ArrayOne operator=(const ArrayOne &arrayOne)const;
ArrayOne(const ArrayOne &arrayOne);
private:
int vec;
};
ArrayOne operator +=(const ArrayOne &a, const ArrayOne &d);
//ArrayOnecpp
#include "ArrayOneh"
#include<iostream>
ArrayOne::ArrayOne(const int init) {
vec = new int[10];
for (int i = 0; i < 10; i++) {
vec[i] = init[i];
}
}
ArrayOne::ArrayOne(const ArrayOne& arrayOne) {
vec = new int[10];
std::cout << "拷贝构造:"<<arrayOnevec[0] << std::endl;
for (int i = 0; i < 10; i++)
vec[i] = arrayOnevec[i];
}
ArrayOne::ArrayOne() {
std::cout << "默认构造" << std::endl;
vec = new int[10];
for (int i = 0; i < 10; i++)
vec[i] = 0;
}
ArrayOne::~ArrayOne() {
delete[] vec;
}
void ArrayOne::show() {
for (int i = 0; i < 10; i++)
std::cout<<vec[i] << ' ';
std::cout << std::endl;
}
ArrayOne ArrayOne::operator+(const ArrayOne &arrayOne)const {
ArrayOne sum;
for (int i = 0; i<10; i++)
sumvec[i] = vec[i] + arrayOnevec[i];
return sum;
}
ArrayOne ArrayOne::operator=(const ArrayOne &arrayOne)const {
for (int i = 0; i<10; i++)
vec[i] = vec[i] + arrayOnevec[i];
return this;
}
ArrayOne operator +=(const ArrayOne &a, const ArrayOne &d) {
for (int i = 0; i<10; i++)
avec[i] += dvec[i];
return a;
}
//maincpp
#include"ArrayOneh"
int main() {
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
int b[10] = { 4,5,6,7,8,9,10,11,12,13 };
ArrayOne arr1(a), arr2(b),arr3;
arr3 = arr1 + arr2;
arr3show();
arr1 += arr2;
arr1show();
return 0;
}
#include<iostream>
#include <typeinfo>
using namespace std;
class String//定义一个链表结点类
{
public:
String(char c[4]);
char readc() const;
private:
char cdata;
String prior;
String next;
};
String::String(char c[4])
{
cout<<"Node constructor is running"<<endl;
cdata = new char[strlen(c)+1];
strcpy(cdata, c);
prior=NULL;
next=NULL;
}
char String::readc() const
{
return cdata;
}int main()
{
String a("dfgh");
cout<<areadc()<<endl;
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)