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 |
#include "Header.h"
|
C-/C++-Quelltext |
|
1 |
#include "header.h"
|
C-/C++-Quelltext |
|
1 |
#include <header.h> |
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 |
#include <iostream> #include <header.h> using namespace std; int main(int argc, char** argv) { float x, y; ball Ball1; ball Ball2(10.0, 10.0); ball *pBall3 = 0; x = Ball1.GetX(); y = Ball1.GetY(); cout << printf("Ball1: X = %f, Y = %f", x, y) << endl; x = Ball2.GetX(); y = Ball2.GetY(); cout << printf("Ball2: X = %f, Y = %f", x, y) << endl; pBall3 = new ball(0.1, -66.0); x = pBall3->GetX(); y = pBall3->GetY(); cout << printf("pBall3: X = %f, Y = %f", x, y) << endl; return 0; } |
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 |
#pragma once class ball { public: float x, y, dx, dy; ball() { this->x = 0; this->y = 0; this->dx = 0; this->dy = 0; } ball(float x, float y) { this->x = x; this->y = y; this->dx = 0; this->dy = 0; } ~ball(){}; float GetX() { return this->x; } float GetY() { return this->y; } int SetPos(float x, float y) { this->x = x; this->y = y; return 0; } int update() { this->x += this->dx; this->y += this->dy; return 0; } }; |
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 |
#if !defined(BALL_H__INCLUDED) #define BALL_H__INCLUDED #if (_MSC_VER > 1000) #pragma once #endif // _MSC_VER > 1000 class ball { public: ball() : m_x(0), m_y(0), m_dx(0), m_dy(0) {} ball(const float& x, const float& y) : m_x(x), m_y(y), m_dx(0, m_dy(0) {} ~ball() {} public: float get_x() const { return m_x; } float get_y() const { return m_y; } public: void set_pos(const float& x, const float& y) { m_x = x; m_y = y; } void update() { m_x += m_dx; m_y += m_dy; } private: float m_x; float m_y; float m_dx; float m_dy; }; #endif // BALL_H__INCLUDED |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> #include "ball.h" int main() { ball inst_one; std::cout << "Ball1: X = " << inst_one.get_x() << ", Y = " << inst_one.get_y() << std::endl; ball inst_two(10.0, 10.0); std::cout << "Ball2: X = " << inst_two.get_x() << ", Y = " << inst_two.get_y() << std::endl; ball* p_inst_three = new ball(0.1, -66.0); std::cout << "Ball3(Heap): X = " << p_inst_three->get_x() << ", Y = " << p_inst_three->get_y() << std::endl; delete p_inst_three; return 0; } |
Werbeanzeige