Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 |
std::copy(vec.begin(), vec.end(), array); // vec > array std::copy(array, array+size, vec.begin()); //arr -> vec |
Zitat von »"kiba"«
So hab ich es verstanden
C-/C++-Quelltext |
|
1 2 |
int foo[] = {16,2,77,29}; std::vector<int> bar (foo, foo + sizeof(foo) / sizeof(int) ); |
C-/C++-Quelltext |
|
1 2 3 |
std::vector<int> foo; //einige Elemente ablegen int* bar = &foo[0]; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
template <typename T, size_t S> std::vector<T> ArrayToVector(T (&Array)[S]) { return std::vector<T>(Array, Array+S); } int main() { int Array[] = {1, 2, 3, 4}; std::vector<int> Vec = ArrayToVector(Array); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#pragma once #ifndef SURFACE_INCLUDED #define SURFACE_INCLUDED template<class T> class surface { public: typedef T color_type; private: int _width; int _height; color_type* _data; public: surface() : _data(0), _width(0), _height(0) { } surface(int width, int height) : _width(width), _height(height), _data(new T[width * height]) { } template<class U> surface(const surface<U>& s) : surface(s.width, s.height) { for (int i = 0; i < _width * _height; ++i) _data[i] = s._data[i]; } template<class U> surface& operator =(const surface<U>& s) { if (_width != s._width || _height != s._height) resize(s._width, s._height); for (int i = 0; i < _width * _height; ++i) _data[i] = s._data[i]; } ~surface() { delete[] _data; } int width() const { return _width; } int height() const { return _height; } const color_type* getBufferPointer() const { return _data; } color_type* getBufferPointer() { return _data; } void resize(int width, int height) { color_type* tmp_data = new T[width*height]; delete[] _data; _width = width; _height = height; _data = tmp_data; } void clear(const color_type& c = color_type()) const { for (int i = 0; i < _width * _height; ++i) _data[i] = c; } const T& operator ()(int x, int y) const { return _data[y*_width + x]; }; T& operator ()(int x, int y) { return _data[y*_width + x]; }; }; #endif // SURFACE_INCLUDED |
Werbeanzeige