Skip to content

Conversation

@Need2BuySSD
Copy link

No description provided.

bool isConnectedTo(const Object& other) const {
for (auto i = 0; i < getPoleCount(); i++) {
for (auto j = 0; j < other.getPoleCount(); j++) {
if (getPole(i)->connectedObjectPole == other.getPole(j)->name) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неверно.
Вы не проверяте, к какому объекту подключен i-ый полюс текущего объекта, равно как и к какому объекту подключен j-ый полюс other.


bool connect(const std::string& poleName, Object& other, const std::string& otherPoleName) {
if (poleName != otherPoleName) {
getPole(poleName)->connectedObject = &other; //const_cast<Object*>(&other)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Было бы неплохо кешировать результат работы getPole().

bool disconnect(const std::string& poleName) {
if (getPole(poleName)->connectedObject) {
getPole(poleName)->connectedObject = nullptr;
getPole(poleName)->connectedObjectPole = "";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вы отключаете полюс со стороны текущего объекта, но не отключаете соответствующий ему полюс другого объекта.

gnr.connect("A1", swtch, "A2");
swtch.connect("A1", lght, "A2");
lght.connect("A1", gnr, "A2");
return 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не хватает демонстрации текущего состояния с выводом на экран.

/// </summary>
/// <param name="b">Изучаемый объект</param>
void printInternals(const B& b) {
void printInternals(B& b) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если вам потребовалось убрать модификатор const чтобы вывести состояние объекта, то что-то явно сделано не так.

std::string getBString() const;
void printData(std::ostream& os);
void printData2(std::ostream& os);
virtual std::string* getBStr() = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Геттер не должны изменять состояние объекта и поэтому могут (и должны) помечаться ключевым словом const.

using namespace std;
class vector3d {
public:
float data[3];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем-то сделали публичным.

#include "vector.h"

using namespace std;
class vector3d {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У вас и здесь класс vector3d, и в заголовочном файле. Это, в принципе, не может компилироваться.

@Need2BuySSD Need2BuySSD requested a review from grayed June 10, 2022 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants