Results 1 to 5 of 5
Thread: C++
Hybrid View
-
16th December 2005 20:28 #1Registered User
Join Date: Jun:2005
Location: Sofia
Posts: 12
C++
, , , ( , ) : , - . .
-
16th December 2005 20:49 #2[bg] [/bg]Code:
struct Vector { double x, y; Vector(double x = 0, double y = 0) : x(x), y(y) { } }; Vector operator+(const Vector& lhs, const Vector& rhs) { return Vector(lhs.x + rhs.x, lhs.y + rhs.y); }
... -:
Code:Vector a(5, 10); Vector b(15, 20); Vector c = a + b;
-
17th December 2005 02:43 #3
- : :
, GenericVector<3>. :Code:#include <iostream> #include <sstream> using namespace std; template <int _size> class GenericVector { double v[_size]; public: GenericVector(const char *init = "") { int i = 0; double t; stringstream ss(init); while (i < _size && ss >> t) { v[i++] = t; } while (i < _size) v[i++] = 0.0; } GenericVector operator + (const GenericVector & r) { GenericVector bla; for (int i = 0; i < _size; i++) { bla.v[i] = v[i] + r.v[i]; } return bla; } void print() const { cout << "("; for (int i = 0; i < _size; i++) cout << v[i] << (i < _size-1?", ":""); cout << ")" << endl; } };
Code:GenericVector<3> a("5 -3 10"); GenericVector<3> b("6 0 -12"); GenericVector<3> c = a + b; c.print();
Code:(11, -3, -2)
, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
17th December 2005 15:31 #4Registered User
Join Date: Jun:2005
Location: Sofia
Posts: 12
?
-
17th December 2005 18:40 #5
Last edited by singularity; 12th April 2007 at 14:05. Reason:
ignore list:Java,velio,jaredharet,gochev.george,Nit rogeniumQuis custodiet ipsos custodes?




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in