Bonsoir,

Je suis en train de créer une bibliothèque personnelle pour travailler avec la logique floue et la régulation au travers de cette logique. J'ai créé une classe abstraite pour gérer les ports (entrées et sorties) pour les grandeurs physiques et ceux pour les valeurs logiques. Voici le code de l'en-tête et le code source:
Code abstractport.h : Sélectionner tout - Visualiser dans une fenêtre à part
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
#ifndef ABSTRACTPORT_H
#define ABSTRACTPORT_H
 
class AbstractPort
{
    //Public members
    public:
        //Enumeration
        enum Type
        {
            Unknown, Fuzzy, Physical
        };
 
        //Constructors
        AbstractPort();
        AbstractPort(const Type& type, const double& value);
        AbstractPort(const AbstractPort& other);
 
        //Destructor
        ~AbstractPort();
 
        //Getters
        double value() const;
        Type type() const;
 
        //Setter
        void setValue(const double& newVal);
 
        //Overloaded assignment operator
        AbstractPort operator=(const AbstractPort& other);
 
        //Overloaded relational operators
        bool operator==(const AbstractPort& other) const;
        bool operator!=(const AbstractPort& other) const;
 
    //Private members
    private:
        //Data fields
        Type m_type;
        double m_value;
 
    //Protected members
    protected:
        //Protected setter
        void setType(const Type& type);
 
        //Methods to reimplement
        virtual void furtherAssignment(const AbstractPort& other) = 0;
        virtual bool furtherConditionAboutNewValue(double newValue) const = 0;
        virtual bool furtherEqualityTest(const AbstractPort& other) const = 0;
};
 
#endif // ABSTRACTPORT_H
Code abstractport.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include "abstractport.h"
 
AbstractPort::AbstractPort() :
    m_type  (AbstractPort::Unknown) ,
    m_value (0.0f)
{
 
}
 
AbstractPort::AbstractPort(const AbstractPort::Type& type, const double& value) :
    m_type  (type) ,
    m_value (value)
{
 
}
 
AbstractPort::AbstractPort(const AbstractPort& other) :
    m_type  (other.type()) ,
    m_value (other.value())
{
 
}
 
AbstractPort::~AbstractPort()
{
 
}
 
AbstractPort::Type AbstractPort::type() const
{
    return this->m_type;
}
 
double AbstractPort::value() const
{
    return this->m_value;
}
 
void AbstractPort::setValue(const double& newVal)
{
    if(furtherConditionAboutNewValue(newVal) && (newVal != m_value))
    {
        m_value = newVal;
    }
}
 
AbstractPort AbstractPort::operator=(const AbstractPort& other)
{
    if(*this == other)
    {
        this->m_type = other.type();
        this->m_value = other.value();
        furtherAssignment(other);
    }
    return *this;
}
 
bool AbstractPort::operator==(const AbstractPort& other) const
{
    return ((this->m_type == other.type()) && (this->m_value == other.value()) && furtherEqualityTest(other));
}
 
bool AbstractPort::operator!=(const AbstractPort& other) const
{
    return !(*this == other);
}
 
void AbstractPort::setType(const AbstractPort::Type& type)
{
    m_type = type;
}
Cependant, il y a un problème. Mon compilateur, MinGW, me renvoie des erreurs sur l'opérateur = que j'ai surchargé. Voici les erreurs:
  • Type de retour non-valide car abstrait (dans le fichier d'en-tête et le fichier source);
  • Allocation impossible d'un objet d'une classe abstraite (seulement dans le fichier source).

Honnêtement, je ne vois pas comment corriger ce problème; c'est pourquoi je demande votre aide.

Merci d'avance.

Adishatz!