C++调用构造函数

来源:百度知道 编辑:UC知道 时间:2024/05/31 15:35:19
#include <iostream>
using namespace std;
class Sort
{
public:
Swap(char x[],char y[]);
InsertionSort(int a[],int n,Sort &temp);
SelectionSort(char b[],char m);
private:
int X;char x[20],y[20],z[20];
int a[20];
char b[20];

};
Sort::InsertionSort(int a[],int n,Sort &temp)
{
X=temp.a[20];
int i,j;
for(i=1;i<n;i++)
{
i=j;
X=a[i];
while(j>0 &&X<a[j-1])
{
a[j]=a[j-1];
j--;
}
a[j]=X;
}
}
Sort::Swap(char x[],char y[])
{
char z[20];
x[19]=z[19];
x[19]=y[19];
y[19]=z[19];
}
Sort::SelectionSort(char b[],char m)
{
char smallindex;
char c,d;
for(c=0;c<m-1;c++)
{
smallindex=c;
for(d=c+1;d<m;d++)
if(b[d]<b[smallindex])
smallindex=d;
Swap(&b[c],&b[smallindex]);
}
}
vo

你不写默认构造函数的话,编译器在需要的时候会自动合成
你要写的就是下面的哦,没有什么特殊需要的话
Sort::Sort(void)
{
}

定义对象啊
Sort mySort;

晕,你主函数里都没有用类去定义对像,怎么会调用构造函数呢.
只有当你用类去定义对像时才调用构造函数开辟空间