#include<iostream>#include<cmath>using namespace std;class point {public: point(int xx=0,int yy=0) { x=xx; y=yy; } point(point &p); int getx(){return x;} int gety(){return y;}private: int x,y;};point::point(point &p) { x=p.x; y=p.y; cout<<"復制建構式被呼叫"<<endl;}class line {public: line(point xp1,point xp2); line(line &1); double getlen(){return len;}private: point p1,p2; double len;};line::line(point xp1,point xp2):p1(xp1),p2(xp2) { cout<<"建構式被呼叫"<<endl; double x=double(p1.getx()-p2.getx()); double y=double(p1.gety()-p2.gety()); len=sqrt(x*x+y*y);}line::line(line &1):p1(1.p1),p2(1.p2) { cout<<"復制建構式被呼叫"<<endl; len=1.len;}int main(){ point myp1(1,1),myp2(4,5); line line(myp1,myp2); line line2(line); cout<<"線段長度為:"<<line.getlen()<<endl; cout<<"線段2長度為:"<<line2.getlen()<<endl; return 0;}
uj5u.com熱心網友回復:
不好意思,圖發不出來,錯誤如下unexpceted class line(
Unexpected token(s) preceding;
missing ) before constant
missing ; before constant
unexpected end of file found
uj5u.com熱心網友回復:
這代碼有點亂uj5u.com熱心網友回復:
看上去像是缺少啥后括號?或者分號?或者其它問題。經常回遇到雖然說你可能哪兒少了啥分號啊,后括號啊,但錯誤的實際情況、實際位置可能不一定和他報錯的地方一樣
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/104454.html
標籤:C++ 語言
下一篇:c語言如何判斷某一天是否為生日?
