T
ttxyy
Unregistered / Unconfirmed
GUEST, unregistred user!
以下程序已经在TC++3.0下编译通过。
#include <iostream.h>
class P
{
public:
P(int P1,int p2)
{pri1=p1;pri2=p2;}
int inc1()
{return ++pri1;}
void display()
{cout<<"pri1="<<pri1<<",pri2="<<pri2<<
endl;}
private:
int pri1,pri2;
};
class D1:virtual private P
{
public:
D1(int p1,int p2,int p3)(p1,p2)
{pri3=p3;}
int inc3()
{return ++pri3;}
void display()
{
P::display();
cout<<"pri3="<<pri3<<
endl;
}
private:
int pri3;
};
class D2: virtual public P
{
public:
D2(int p1,int p2,int p4)(p1,p2)
{pri4=p4;}
int inc4()
{return ++pri4;}
void display()
{
P::display();
cout<<"pri4="<<pri4<<
endl;
}
private:
int pri4;
};
class D12rivate D1,public D2
{
public:
D12(int p11,int p12,int p13,int p21,int p22,int p23,int p)1(p11,p12,p13),D2(p21,p22,p23),P(p11,p21)
{pri12=p;}
int inc5()
{return ++pri12;}
void display()
{
cout<<"D2::display()/n";
D2::display();
cout<<"pri12="<<pri12<<
endl;
}
private:
int pri12;
};
void main()
{
D12 d(1,2,3,4,5,6,7);
d.display();
cout<<
endl;
d.inc1();
d.inc4();
d.inc5();
d.D12::inc1();
d.display();
}
可是我将这个程序分成三部分:即头文件、实现文件、调用文件时,编译时没有出错错误,可是在链接时却提示出错了:
Linker Error: Undefined symbol D12::display() in module ../../MAIN.cpp
以下是将上面的文件一分为三的具体的文件,请高手帮我啊:
头文件kkk.h
class P
{
public:
P(int p1,int p2)
{pri1=p1;pri2=p2;}
int inc1()
{return ++pri1;}
void display();
private:
int pri1,pri2;
};
class D1:virtual private P
{
public:
D1(int p1,int p2,int p3)(p1,p2)
{pri3=p3;}
int inc3()
{return ++pri3;}
void display();
private:
int pri3;
};
class D2: virtual public P
{
public:
D2(int p1,int p2,int p4)(p1,p2)
{pri4=p4;}
int inc4()
{return ++pri4;}
void display();
private:
int pri4;
};
class D12rivate D1,public D2
{
public:
D12(int p11,int p12,int p13,int p21,int p22,int p23,int p)1(p11,p12,p13),D2(p21,p22,p23),P(p11,p21)
{pri12=p;}
int inc5()
{return ++pri12;}
void display();
private:
int pri12;
};
实现文件kkk.cpp
#include <iostream.h>
#include "kkk.h"
void P::display()
{cout<<"pri1="<<pri1<<",pri2="<<pri2<<
endl;}
void D1::display()
{
P::display();
cout<<"pri3="<<pri3<<
endl;
}
void D2::display()
{
P::display();
cout<<"pri4="<<pri4<<
endl;
}
void D12::display()
{
cout<<"D2::display()/n";
D2::display();
cout<<"pri12="<<pri12<<
endl;
}
主文件main.cpp
#include <iostream.h>
#include "kkk.h"
void main()
{
D12 d(1,2,3,4,5,6,7);
d.display();
cout<<
endl;
d.inc1();
d.inc4();
d.inc5();
d.D12::inc1();
d.display();
}
#include <iostream.h>
class P
{
public:
P(int P1,int p2)
{pri1=p1;pri2=p2;}
int inc1()
{return ++pri1;}
void display()
{cout<<"pri1="<<pri1<<",pri2="<<pri2<<
endl;}
private:
int pri1,pri2;
};
class D1:virtual private P
{
public:
D1(int p1,int p2,int p3)(p1,p2)
{pri3=p3;}
int inc3()
{return ++pri3;}
void display()
{
P::display();
cout<<"pri3="<<pri3<<
endl;
}
private:
int pri3;
};
class D2: virtual public P
{
public:
D2(int p1,int p2,int p4)(p1,p2)
{pri4=p4;}
int inc4()
{return ++pri4;}
void display()
{
P::display();
cout<<"pri4="<<pri4<<
endl;
}
private:
int pri4;
};
class D12rivate D1,public D2
{
public:
D12(int p11,int p12,int p13,int p21,int p22,int p23,int p)1(p11,p12,p13),D2(p21,p22,p23),P(p11,p21)
{pri12=p;}
int inc5()
{return ++pri12;}
void display()
{
cout<<"D2::display()/n";
D2::display();
cout<<"pri12="<<pri12<<
endl;
}
private:
int pri12;
};
void main()
{
D12 d(1,2,3,4,5,6,7);
d.display();
cout<<
endl;
d.inc1();
d.inc4();
d.inc5();
d.D12::inc1();
d.display();
}
可是我将这个程序分成三部分:即头文件、实现文件、调用文件时,编译时没有出错错误,可是在链接时却提示出错了:
Linker Error: Undefined symbol D12::display() in module ../../MAIN.cpp
以下是将上面的文件一分为三的具体的文件,请高手帮我啊:
头文件kkk.h
class P
{
public:
P(int p1,int p2)
{pri1=p1;pri2=p2;}
int inc1()
{return ++pri1;}
void display();
private:
int pri1,pri2;
};
class D1:virtual private P
{
public:
D1(int p1,int p2,int p3)(p1,p2)
{pri3=p3;}
int inc3()
{return ++pri3;}
void display();
private:
int pri3;
};
class D2: virtual public P
{
public:
D2(int p1,int p2,int p4)(p1,p2)
{pri4=p4;}
int inc4()
{return ++pri4;}
void display();
private:
int pri4;
};
class D12rivate D1,public D2
{
public:
D12(int p11,int p12,int p13,int p21,int p22,int p23,int p)1(p11,p12,p13),D2(p21,p22,p23),P(p11,p21)
{pri12=p;}
int inc5()
{return ++pri12;}
void display();
private:
int pri12;
};
实现文件kkk.cpp
#include <iostream.h>
#include "kkk.h"
void P::display()
{cout<<"pri1="<<pri1<<",pri2="<<pri2<<
endl;}
void D1::display()
{
P::display();
cout<<"pri3="<<pri3<<
endl;
}
void D2::display()
{
P::display();
cout<<"pri4="<<pri4<<
endl;
}
void D12::display()
{
cout<<"D2::display()/n";
D2::display();
cout<<"pri12="<<pri12<<
endl;
}
主文件main.cpp
#include <iostream.h>
#include "kkk.h"
void main()
{
D12 d(1,2,3,4,5,6,7);
d.display();
cout<<
endl;
d.inc1();
d.inc4();
d.inc5();
d.D12::inc1();
d.display();
}