Я только что переключился с Java на C ++, и пока все идет довольно хорошо. Язык довольно сложный, но я чувствую, как будто я понимаю. У меня есть вопрос о деструкторах, и для этого я предоставлю свой текущий код в надежде, что кто -то сможет дать некоторые разъяснения о том, что и как я должен продолжить. Моя проблема начинается так, у моего кубоида есть экземпляр как Vector3D, так и Dimension3d, который вы скоро увидите. Мне нужно знать, как (точная процедура) того, что происходит с моим кубоидным классом, когда он будет помечен для удаления. Или точнее, если мне нужно явно уничтожить как экземпляр Vector3D, так и Dimension3D, когда происходит такое событие. Я надеюсь, что я сформулировал этот вопрос достаточно адекватно. < /P>
Вот мои классы.#include "Vector3D.h"
Vector3D::Vector3D(){
}
Vector3D::Vector3D( const float& x , const float& y , const float& z ){
this->x = x;
this->y = y;
this->z = z;
}
Vector3D::~Vector3D(){
}
void Vector3D::setX( const float& x ){
this->x = x;
}
void Vector3D::setY( const float& y ){
this->y = y;
}
void Vector3D::setZ( const float& z ){
this->z = z;
}
float Vector3D::getX(){
return x;
}
float Vector3D::getY(){
return y;
}
float Vector3D::getZ(){
return z;
}
< /code>
(vector3d.h)
#ifndef NE3_Vector3D_H_
#define NE3_Vector3D_H_
class Vector3D{
public:
Vector3D();
Vector3D( const float& , const float& , const float& );
~Vector3D();
void setX( const float& );
void setY( const float& );
void setZ( const float& );
void setPosition( const float& , const float& , const float& );
float getX();
float getY();
float getZ();
float x;
float y;
float z;
private:
// Private Members Go Here
};
#endif // NE3_Vector3D_H_
< /code>
(dimension3d.cpp)
#include "Dimension3D.h"
Dimension3D::Dimension3D(){
}
Dimension3D::Dimension3D( const float& width , const float& height , const float& depth ){
this->width = width;
this->height = height;
this->depth = depth;
}
Dimension3D::~Dimension3D(){
}
void Dimension3D::setWidth( const float& width ){
this->width = width;
}
void Dimension3D::setHeight( const float& height ){
this->height = height;
}
void Dimension3D::setDepth( const float& depth ){
this->depth = depth;
}
float Dimension3D::getWidth(){
return width;
}
float Dimension3D::getHeight(){
return height;
}
float Dimension3D::getDepth(){
return depth;
}
< /code>
(dimension3d.h)>
#ifndef NE3_Dimension3D_H_
#define NE3_Dimension3D_H_
class Dimension3D{
public:
Dimension3D();
Dimension3D( const float& , const float& , const float& );
~Dimension3D();
void setWidth( const float& );
void setHeight( const float& );
void setDepth( const float& );
void setSize( const float& , const float& , const float& );
float getWidth();
float getHeight();
float getDepth();
float width;
float height;
float depth;
private:
// Private Members Go Here
};
#endif // NE3_Dimension3D_H_
< /code>
И, наконец, моя работа в прогрессе Cuboid.cpp и Cuboid.h < /p>
(cuboid.cpp)
#include "Cuboid.h"
Cuboid::Cuboid(){
}
Cuboid::Cuboid(const Vector3D& location, const Dimension3D& dimension){
this->location = location;
this->dimension = dimension;
}
Cuboid::~Cuboid(){
// Do i do delete both location and dimension here?
}
void Cuboid::drawImmediate(){
}
void Cuboid::drawVBO(){
}
< /code>
(cuboid.h)
#ifndef NE3_CUBOID_H_
#define NE3_CUBOID_H_
#include "Vector3D.h"
#include "Dimension3D.h"
class Cuboid{
public:
Cuboid();
Cuboid( const Vector3D& , const Dimension3D& );
~Cuboid();
void drawImmediate();
void drawVBO();
Vector3D location;
Dimension3D dimension;
private:
};
#endif // NE3_CUBOID_H_
< /code>
Я оставил комментарий в cuboid.cpp в деструкторе. Я хочу знать, должен ли я удалить там Vector3D и Dimension3d, и пример, показывающий лучший способ сделать это. IE: Любые общие соглашения, которые выражают эту функциональность. Кроме того, я уверен, что есть другие вопросы, подобные этому, однако мне нужно увидеть это в моем собственном коде, чтобы полностью понять его. (Странный стиль обучения), поэтому, пожалуйста, простите меня, если это превратится в дубликат.
Подробнее здесь: https://stackoverflow.com/questions/220 ... destructor
Должен ли я явно уничтожить членов класса в деструкторе? ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1758975927
Anonymous
Я только что переключился с Java на C ++, и пока все идет довольно хорошо. Язык довольно сложный, но я чувствую, как будто я понимаю. У меня есть вопрос о деструкторах, и для этого я предоставлю свой текущий код в надежде, что кто -то сможет дать некоторые разъяснения о том, что и как я должен продолжить. Моя проблема начинается так, у моего кубоида есть экземпляр как Vector3D, так и Dimension3d, который вы скоро увидите. Мне нужно знать, как (точная процедура) того, что происходит с моим кубоидным классом, когда он будет помечен для удаления. Или точнее, если мне нужно явно уничтожить как экземпляр Vector3D, так и Dimension3D, когда происходит такое событие. Я надеюсь, что я сформулировал этот вопрос достаточно адекватно. < /P>
Вот мои классы.#include "Vector3D.h"
Vector3D::Vector3D(){
}
Vector3D::Vector3D( const float& x , const float& y , const float& z ){
this->x = x;
this->y = y;
this->z = z;
}
Vector3D::~Vector3D(){
}
void Vector3D::setX( const float& x ){
this->x = x;
}
void Vector3D::setY( const float& y ){
this->y = y;
}
void Vector3D::setZ( const float& z ){
this->z = z;
}
float Vector3D::getX(){
return x;
}
float Vector3D::getY(){
return y;
}
float Vector3D::getZ(){
return z;
}
< /code>
(vector3d.h)
#ifndef NE3_Vector3D_H_
#define NE3_Vector3D_H_
class Vector3D{
public:
Vector3D();
Vector3D( const float& , const float& , const float& );
~Vector3D();
void setX( const float& );
void setY( const float& );
void setZ( const float& );
void setPosition( const float& , const float& , const float& );
float getX();
float getY();
float getZ();
float x;
float y;
float z;
private:
// Private Members Go Here
};
#endif // NE3_Vector3D_H_
< /code>
(dimension3d.cpp)
#include "Dimension3D.h"
Dimension3D::Dimension3D(){
}
Dimension3D::Dimension3D( const float& width , const float& height , const float& depth ){
this->width = width;
this->height = height;
this->depth = depth;
}
Dimension3D::~Dimension3D(){
}
void Dimension3D::setWidth( const float& width ){
this->width = width;
}
void Dimension3D::setHeight( const float& height ){
this->height = height;
}
void Dimension3D::setDepth( const float& depth ){
this->depth = depth;
}
float Dimension3D::getWidth(){
return width;
}
float Dimension3D::getHeight(){
return height;
}
float Dimension3D::getDepth(){
return depth;
}
< /code>
(dimension3d.h)>
#ifndef NE3_Dimension3D_H_
#define NE3_Dimension3D_H_
class Dimension3D{
public:
Dimension3D();
Dimension3D( const float& , const float& , const float& );
~Dimension3D();
void setWidth( const float& );
void setHeight( const float& );
void setDepth( const float& );
void setSize( const float& , const float& , const float& );
float getWidth();
float getHeight();
float getDepth();
float width;
float height;
float depth;
private:
// Private Members Go Here
};
#endif // NE3_Dimension3D_H_
< /code>
И, наконец, моя работа в прогрессе Cuboid.cpp и Cuboid.h < /p>
(cuboid.cpp)
#include "Cuboid.h"
Cuboid::Cuboid(){
}
Cuboid::Cuboid(const Vector3D& location, const Dimension3D& dimension){
this->location = location;
this->dimension = dimension;
}
Cuboid::~Cuboid(){
// Do i do delete both location and dimension here?
}
void Cuboid::drawImmediate(){
}
void Cuboid::drawVBO(){
}
< /code>
(cuboid.h)
#ifndef NE3_CUBOID_H_
#define NE3_CUBOID_H_
#include "Vector3D.h"
#include "Dimension3D.h"
class Cuboid{
public:
Cuboid();
Cuboid( const Vector3D& , const Dimension3D& );
~Cuboid();
void drawImmediate();
void drawVBO();
Vector3D location;
Dimension3D dimension;
private:
};
#endif // NE3_CUBOID_H_
< /code>
Я оставил комментарий в cuboid.cpp в деструкторе. Я хочу знать, должен ли я удалить там Vector3D и Dimension3d, и пример, показывающий лучший способ сделать это. IE: Любые общие соглашения, которые выражают эту функциональность. Кроме того, я уверен, что есть другие вопросы, подобные этому, однако мне нужно увидеть это в моем собственном коде, чтобы полностью понять его. (Странный стиль обучения), поэтому, пожалуйста, простите меня, если это превратится в дубликат.
Подробнее здесь: [url]https://stackoverflow.com/questions/22095902/should-i-explicitly-destroy-class-members-in-the-destructor[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия