Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误:变量‘';具有初始值设定项,但类型不完整_C++_Templates_Incomplete Type - Fatal编程技术网

C++ 错误:变量‘';具有初始值设定项,但类型不完整

C++ 错误:变量‘';具有初始值设定项,但类型不完整,c++,templates,incomplete-type,C++,Templates,Incomplete Type,我有我的班级直方图: typedef unsigned long int ulong; typedef unsigned short int ushort; typedef unsigned char ubyte; typedef unsigned int uint; #include "Image.h" #include <iostream> class Histogram { static const ushort NB_MAX = 256; uint hi

我有我的班级直方图:

typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned char ubyte;
typedef unsigned int uint;

#include "Image.h"
#include <iostream>


class Histogram
{
    static const ushort NB_MAX = 256;
    uint histo[NB_MAX];
    uint grisMax;

public:

    Histogram(const GrayImage &gi);
    GrayImage* draw() const;
};

const ushort Histogram::NB_MAX;

/* END OF CLASS */
我看到很多关于这类错误的帖子,但什么也没有看到。。
有人知道问题的来源吗?

const-ushort直方图::NB_MAX
为此,您需要完整的
直方图定义。仅仅宣布朋友是不够的。对我来说,这是一段糟糕的过去。const ushort Histogram::NB_MAX位于直方图上,这不是问题^^是否包括包含类定义的标题?如果可能,包括:)typedef Image GrayImage;typedef图像彩色图像;应放置在图像中。h
     #ifndef TP3_C___Image_h
#define TP3_C___Image_h


#include <iostream>
#include <cstdlib>
#include <sstream>
#include <stdexcept>
#include <vector>
#include <stdio.h>
#include <algorithm>

extern "C" {
#include <jpeglib.h> /* Ce sont des déclarations relatives à des fonctions C ! */
}

#include "Color.h"

#include <cmath>

typedef unsigned short int ushort;
typedef unsigned long int ulong;
typedef unsigned char ubyte;
typedef unsigned int uint;


template <typename T>
class Image
{
    friend class Histogram;

    /**
     * Longueur et largeur
     */
    ushort width, height;

    /**
     * Tableau d'images
     */
    T *array;


public:

    /**
     * Constructeur de la classe
     */
    Image(const ushort &w,const ushort &h);


    /**
     * Constructeur de copie
     */
    Image(const Image<T> &img);

    /**
     * Destructeur
     */
    ~Image();


/**
 * Méthode renvoyant une réference sur le pixel de
 * coordonnée x,y
 */
T &pixel(ushort, ushort);

/**
 * Méthode renvoyant le niveau de gris
 * correspondant au pixel de coordonée x,y
 */
const T& pixel(ushort x, ushort y) const;

/**
 * Retourne la largeur de l'image
 */
const ushort& getWidth() const;

/**
 * Retourne la hauteur de l'image
 */
const ushort& getHeight() const;

/**
 * Méthode initialisant les points de l'image
 */
void clear(T color = 0);

/**
 * Trace dans l'image un cadre rectangulaire (d'un pixel d'épaisseur) de la couleur color
 * dont le coin supérieur gauche est à la coordonnée (x,y) et dont la largeur et la hauteur
 * sont respectivement w et h.
 */
void rectangle(ushort x, ushort y, ushort w, ushort h, T color);

void line(ushort x0, ushort y0, ushort x1, ushort y1 , const Color couleur);

/**
 * Trace un rectangle plein sur le même principe que la précédante.
 */
void fillRectangle(ushort x, ushort y, ushort w, ushort h, T color);

/**
 *  Écrit à l'interieur du fichier PGM
 */
void writePGM(std::ostream&) const;

/**
 *  Écrit à l'interieur du fichier PPM
 */
void writePPM(std::ostream&) const;
void writeTGA(std::ostream&, bool rle = true) const;

/**
 *  Écrit à l'interieur du fichier JPEG
 */
void writeJPEG(const char*, unsigned int quality = 75) const;

Image<ubyte>* floydSteinberg() const;


/**
 *  Lit une image au format PGM
 */
static Image<ubyte>* readPGM(std::istream&);
static Image<Color>* readPPM(std::istream&);
static Image<Color>* readTGA(std::istream&);
static Image<Color>* readJPEG(char*);
Image<Color>* simpleScale(ushort, ushort) const;

Image<Color>* bilinearScale(ushort, ushort) const;
Image<ubyte>* threshold(ubyte thresh= 128) const;
Image<ubyte>* randomDither() const;};

 typedef Image<ubyte> GrayImage;
 typedef Image<Color> ColorImage;
     #include <iostream>
     #include <iomanip>
#include <fstream>
#include <memory>
#include <cmath>
#include "Image.h"
#include "Histogram.h"

using namespace std;

typedef Image<ubyte> GrayImage;
typedef Image<Color> ColorImage;


int main()
{
    try
    {
        //========================================
        // Pour créer un rectangle vide et plein
        //========================================

        GrayImage gi(200,400); /* Une image en gris */
        ofstream os("rectangle.pgm", ios::binary);
        gi.clear(100);
        gi.fillRectangle(0, 0, 2,2, 244);
        gi.rectangle(0, 52, 50, 100, 244);
        gi.writePGM(os);


        //=========================================================
        // Pour lire une image, écrire par dessus et l'enregistrer
        //=========================================================

        ifstream ifsPgm("chat.pgm", ios::binary);
        auto_ptr<GrayImage> ptrGray(GrayImage::readPGM(ifsPgm)); /* Une image en gris */
        ptrGray->fillRectangle(0, 0, 50,100, 222);
        ptrGray->rectangle(70, 70, 50, 100, 244);
        ofstream chatOutPut("chatWrite.pgm", ios::binary);
        ptrGray->writePGM(chatOutPut);


        //=================================================
        // Pour lire une image et déssiner son histogramme
        //=================================================

        ifstream ifsHisto("chat.pgm", ios::binary);
        ofstream histogramOutPut("histogram.pgm", ios::binary);
        ptrGray.reset(GrayImage::readPGM(ifsHisto)); 
        if(ptrGray.get()) {
            Histogram histo(*ptrGray);
            auto_ptr<GrayImage> myHisto(histo.draw());
            myHisto->writePGM(histogramOutPut);}
 error: variable ‘Histogram histo’ has initializer but incomplete type