使用“interface”时,在类中没有声明成员函数

时间:2016-01-28 20:04:36

标签: c++ inheritance interface

我想用一些静态方法实现一个接口Formatter,然后创建另一个实现该方法的类。我做了类似的事情:

Formatter.hpp

#include <iostream>
#include <string>
#include "Matrix.hpp"

#ifndef FORMATTER_HPP
#define FORMATTER_HPP

class Formatter {
public:
    /**
     * Retorna uma string que pode ser usada no symbolab para testes
     */
    static std::string matrixString(Matrix* matrix);
    /**
     * Retorna string para symbolab para transposição da matriz
     */
    static std::string transposedMatrixString(Matrix* matrix);
    /**
     * Retorna string para symbolab da soma de duas matrizes
     */
    static std::string matrixSumString(Matrix* m1, Matrix* m2);
    /**
     * Retorna string para symbolab do produto de duas matrizes
     */
    static std::string matrixProductString(Matrix* m1, Matrix* m2);
    /**
     * Retorna string para symbolab da determinante de uma matriz
     */
    static std::string matrixDeterminantString(Matrix* matrix);
};

#endif

SymbolabFormatter.hpp

#include <iostream>
#include "Formatter.hpp"

#ifndef SYMBOLABFORMATTER_HPP
#define SYMBOLABFORMATTER_HPP

class SymbolabFormatter: public Formatter{
public:
    SymbolabFormatter();
};

#endif

SymbolabFormatter.cpp

#include "SymbolabFormatter.hpp"
#include <sstream>

std::string SymbolabFormatter::matrixString(Matrix* matrix) {
    ...
}

std::string SymbolabFormatter::transposedMatrixString(Matrix *matrix) {
    ...
}

std::string SymbolabFormatter::matrixSumString(Matrix *m1, Matrix *m2) {
    ...
}

std::string SymbolabFormatter::matrixProductString(Matrix *m1, Matrix *m2) {
    ...
}

std::string SymbolabFormatter::matrixDeterminantString(Matrix* matrix) {
    ...
}

但是不起作用。当我编译时,会显示以下错误: Image from compiler

PS。:抱歉一些语法错误,我的英语很糟糕。

1 个答案:

答案 0 :(得分:3)

除非您将其声明为类的成员函数,否则无法定义SymbolabFormatter::matrixString

在基类中声明成员函数并不等于在派生类中声明它。