65,211
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <iostream>
using namespace std;
class Time
{
private:
int me;
public:
int hour;
int minute;
int second;
static int number;
Time(int h,int m,int s);
void getTime();
friend void display(Time &t);
};
template <class numtype1,class numtype2>
class Cl
{
public:
numtype1 a;
numtype2 b;
Cl(numtype1 n,numtype2 m) ;
void display1() ;
};
//关于继承中强制类型的转换
class A
{
private:
int a;
public:
A(int a)
{
this->a=a;
}
virtual ~A()
{
cout <<"this is A del" <<endl;
}
};
class B:public A
{
private :
int b;
public:
B(int a,int b):A(a)
{
this->b=b;
}
virtual ~B() //将之改为虚析构函数结果将怎样
{
cout <<"this is B del" <<endl;
}
};
class C:public B
{
private:
int c;
public:
C(int a,int b,int c):B(a,b)
{
this->c=c;
}
~C()
{
cout <<"this is C del" <<endl;
}
};
void Time::getTime()
{
cout <<hour <<" :" <<minute <<" :" <<second <<endl;
cout <<number <<endl;
}
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
me=55;
}
int Time::number=10;
void display(Time &t)
{
cout <<t.me <<endl;
}
//这里有问题
template <class numtype1,class numtype2>
void Cl <numtype1,numtype2>::display1()
{
cout <<"a " <<a <<endl;
cout <<"b " <<b <<endl;
}
template <class numtype1,class numtype2>
Cl <numtype1,numtype2>::Cl(numtype1 n,numtype2 m)
{
a=n;b=m;
}
void main()
{
Cl <int,int> c1(12,15);
c1.display1();
}
单文件没有出现问题
d:\Projects>g++ c.c
c.c:129:3: warning: no newline at end of file
d:\Projects>a
a 12
b 15
你把模板的实现分开了...一般不支持这样搞的...
#include <iostream>
using namespace std;
class Time
{
private:
int me;
public:
int hour;
int minute;
int second;
static int number;
Time(int h,int m,int s);
void getTime();
friend void display(Time &t);
};
template <class numtype1,class numtype2>
class Cl
{
public:
numtype1 a;
numtype2 b;
Cl(numtype1 n,numtype2 m);
// {
// a=n;b=m;
// }
void display1();
// {
// cout <<a <<endl;
// cout <<b <<endl;
// }
};
//关于继承中强制类型的转换
class A
{
private:
int a;
public:
A(int a)
{
this->a=a;
}
virtual ~A()
{
cout <<"this is A del" <<endl;
}
};
class B:public A
{
private :
int b;
public:
B(int a,int b):A(a)
{
this->b=b;
}
~B() //将之改为虚析构函数结果将怎样
{
cout <<"this is B del" <<endl;
}
};
class C:public B
{
private:
int c;
public:
C(int a,int b,int c):B(a,b)
{
this->c=c;
}
~C()
{
cout <<"this is C del" <<endl;
}
};
//在实现CPP中
#include <iostream>
//#include"class_point.h"
using namespace std;
void Time::getTime()
{
cout <<hour <<" :" <<minute <<" :" <<second <<endl;
cout <<number <<endl;
}
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
me=55;
}
int Time::number=10;
void display(Time &t)
{
cout <<t.me <<endl;
}
//这里有问题
template <class numtype1,class numtype2>
void Cl <numtype1,numtype2>::display1()
{
cout <<"a " <<a <<endl;
cout <<"b " <<b <<endl;
}
template <class numtype1,class numtype2>
Cl <numtype1,numtype2>::Cl(numtype1 n,numtype2 m)
{
a=n;b=m;
}
#include <iostream>
//#include"class_point.h"
using namespace std;
int main()
{
Cl <int,int> c1(12,15);
c1.display1();
}