fork(1) download
  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4. ////////////////////////////////////////////////////////////////
  5. ////////////////////////////////////////////////////////////////CVector3
  6. class CVector3{
  7. private:
  8. double x;
  9. public:
  10. CVector3();
  11. double getX();
  12. void setX(double);
  13. };
  14. CVector3::CVector3(){
  15. x=0;
  16. }
  17. double CVector3::getX(){
  18. return x;
  19. }
  20. void CVector3::setX(double newX){
  21. x=newX;
  22. }
  23. ////////////////////////////////////////////////////////////////
  24. ////////////////////////////////////////////////////////////////CForce
  25. class CForce{
  26. private:
  27. CVector3 f1;
  28. public:
  29. CForce();
  30. CVector3 getF1();
  31. //void setF1();
  32. };
  33. CForce::CForce(){
  34. f1.setX(0);
  35. }
  36. CVector3 CForce::getF1(){
  37. return f1;
  38. }
  39. ////////////////////////////////////////////////////////////////
  40. ////////////////////////////////////////////////////////////////
  41. int main(int argc, char *argv[])
  42. {
  43. CVector3 v1,v2;
  44. v1.setX(3);
  45. printf("v1.x = %0.2lf\n",v1.getX());
  46.  
  47. CForce F;
  48. //printf("v1.x=%0.2lf\n",F.getF1.getX()); //編譯錯誤 insufficient contextual information to determine type
  49. v2=F.getF1();
  50. printf("v2.x = F.f1.x = %0.2lf\n",v2.getX());
  51. system("PAUSE");
  52. return EXIT_SUCCESS;
  53. }
Success #stdin #stdout #stderr 0s 3296KB
stdin
Standard input is empty
stdout
v1.x = 3.00
v2.x = F.f1.x = 0.00
stderr
sh: PAUSE: not found