IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

cannot allocate an object of abstract type because the following virtual functions are pure within


Sujet :

C++

  1. #1
    Membre très actif
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    427
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 427
    Par défaut cannot allocate an object of abstract type because the following virtual functions are pure within
    Bonjour,

    j'essaie d'impléménter zxing :

    main.cpp
    Code : 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
    72
    73
    74
    75
    76
    77
    78
    #include <iostream>
    #include <stdlib.h>
    #include <stdint.h>
    #include <fstream>
    #include <string>
    #include <zxing/qrcode/QRCodeReader.h>
    #include <zxing/Exception.h>
    #include <zxing/common/GlobalHistogramBinarizer.h>
    #include <zxing/DecodeHints.h>
    #include "BufferBitmapSource.h"
     
    using namespace std; 
    using namespace zxing; 
    using namespace zxing::qrcode;
    using namespace qrviddec; 
     
    int main(int argc, char ** argv)
    {
    	try
    	{
     
     
    		// A buffer containing an image. In your code, this would be an image from your camera. In this 
    		// example, it's just an array containing the code for "Hello!". 
    		uint8_t buffer[] = 
    		{ 
    			255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
    			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
    			255,  0 , 255, 255, 255, 255, 255,  0 , 255, 255,  0 , 255,  0 , 255, 255,  0 , 255, 255, 255, 255, 255,  0 , 255, 
    			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 , 255, 255, 255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 
    			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 ,  0 , 255, 255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 
    			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255, 255,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 
    			255,  0 , 255, 255, 255, 255, 255,  0 , 255, 255, 255, 255,  0 ,  0 , 255,  0 , 255, 255, 255, 255, 255,  0 , 255, 
    			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
    			255, 255, 255, 255, 255, 255, 255, 255, 255,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 
    			255,  0 ,  0 , 255,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 , 255,  0 , 255,  0 , 255, 255, 255, 255, 255,  0 , 255, 
    			255,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255,  0 , 255, 255,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255, 255, 255, 
    			255, 255, 255, 255, 255, 255, 255,  0 , 255,  0 ,  0 ,  0 , 255, 255,  0 ,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255, 
    			255, 255, 255,  0 ,  0 , 255, 255, 255,  0 ,  0 ,  0 , 255,  0 , 255, 255, 255, 255, 255, 255,  0 , 255, 255, 255, 
    			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255,  0 , 255, 255, 255, 255,  0 , 255, 255,  0 , 255,  0 , 255, 255, 
    			255, 255, 255, 255, 255, 255, 255, 255, 255,  0 ,  0 , 255,  0 ,  0 , 255, 255, 255, 255,  0 , 255,  0 ,  0 , 255, 
    			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 255, 255,  0 , 255,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 , 255, 255, 255, 
    			255,  0 , 255, 255, 255, 255, 255,  0 , 255, 255,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 ,  0 ,  0 ,  0 , 255, 255, 255, 
    			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255,  0 , 255, 255,  0 ,  0 , 255,  0 ,  0 , 255,  0 , 255,  0 ,  0 , 255, 
    			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255,  0 , 255,  0 ,  0 ,  0 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 
    			255,  0 , 255,  0 ,  0 ,  0 , 255,  0 , 255, 255,  0 ,  0 , 255, 255, 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
    			255,  0 , 255, 255, 255, 255, 255,  0 , 255,  0 , 255,  0 , 255, 255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255, 
    			255,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 255,  0 , 255,  0 ,  0 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
    			255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
    		}; 
    		int width = 23; 
    		int height = 23; 
     
    		// Convert the buffer to something that the library understands. 
    		Ref<LuminanceSource> source (new BufferBitmapSource(width, height, buffer)); 
     
    		// Turn it into a binary image. 
    		Ref<Binarizer> binarizer (new GlobalHistogramBinarizer(source)); 
    		Ref<BinaryBitmap> image(new BinaryBitmap(binarizer));
     
    		// Tell the decoder to try as hard as possible. 
    		DecodeHints hints(DecodeHints::DEFAULT_HINT); 
    		hints.setTryHarder(true); 
     
    		// Perform the decoding. 
        QRCodeReader reader;
        Ref<Result> result(reader.decode(image, hints));
     
    		// Output the result. 
        cout << result->getText()->getText() << endl;
     
      } 
    	catch (zxing::Exception& e) 
    	{
        cerr << "Error: " << e.what() << endl;
      }
    	return 0; 
    }
    BufferBitmapSource.cpp
    Code : 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
    #include "BufferBitmapSource.h"
    #include <iostream>
     
    namespace qrviddec {
     
    BufferBitmapSource::BufferBitmapSource(int inWidth, int inHeight, unsigned char * inBuffer) 
    {
    	width = inWidth; 
    	height = inHeight; 
    	buffer = inBuffer; 
    }
     
    BufferBitmapSource::~BufferBitmapSource()
    {
    }
     
    int BufferBitmapSource::getWidth() const
    {
    	return width; 
    }
     
    int BufferBitmapSource::getHeight() const
    {
    	return height; 
    }
     
    unsigned char * BufferBitmapSource::getRow(int y, unsigned char * row)
    {
    	if (y < 0 || y >= height) 
    	{
    		fprintf(stderr, "ERROR, attempted to read row %d of a %d height image.\n", y, height); 
    		return NULL; 
    	}
    	// WARNING: NO ERROR CHECKING! You will want to add some in your code. 
    	if (row == NULL) row = new unsigned char[width]; 
    	for (int x = 0; x < width; x ++)
    	{
    		row[x] = buffer[y*width+x]; 
    	}
    	return row; 
    }
     
    unsigned char * BufferBitmapSource::getMatrix()
    {
    	return buffer; 
    }
     
    }
    BufferBitmapSource.h
    Code : 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
    #include <zxing/LuminanceSource.h>
    #include <stdio.h>
    #include <stdlib.h>
    using namespace zxing; 
    namespace qrviddec {
     
    class BufferBitmapSource : public LuminanceSource {
    private:
      int width, height; 
      unsigned char * buffer; 
     
    public:
      BufferBitmapSource(int inWidth, int inHeight, unsigned char * inBuffer); 
      ~BufferBitmapSource(); 
     
      int getWidth() const; 
      int getHeight() const; 
      unsigned char* getRow(int y, unsigned char* row); 
      unsigned char* getMatrix(); 
    }; 
    }
    mais g++ me retourne cette erreur :

    main.cpp:55: error: cannot allocate an object of abstract type 'qrviddec::BufferBitmapSource'
    BufferBitmapSource.h:7: note: because the following virtual functions are pure within 'qrviddec::BufferBitmapSource':
    zxing/qrcode/../LuminanceSource.h:42: note: virtual zxing::ArrayRef<char> zxing::LuminanceSource::getRow(int, zxing::ArrayRef<char>) const
    zxing/qrcode/../LuminanceSource.h:43: note: virtual zxing::ArrayRef<char> zxing::LuminanceSource::getMatrix() const
    BufferBitmapSource.cpp: In constructor 'qrviddec::BufferBitmapSource::BufferBitmapSource(int, int, unsigned char*)':
    BufferBitmapSource.cpp:6: error: no matching function for call to 'zxing::LuminanceSource::LuminanceSource()'
    zxing/LuminanceSource.h:35: note: candidates are: zxing::LuminanceSource::LuminanceSource(int, int)
    zxing/LuminanceSource.h:29: note: zxing::LuminanceSource::LuminanceSource(const zxing::LuminanceSource&)
    merci de votre aide

  2. #2
    Expert confirmé
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 599
    Par défaut
    Bonjour,

    La première erreur d'indique que tu ne peux créer un BufferBitmapSource.
    Le compilateur précise pourquoi : des fonctions virtuelles nécessaires n'ont jamais été définies.
    Puis précise les fonctions jamais définies :
    - zxing::ArrayRef<char> getRow( int, zxing::ArrayRef<char>) const.
    - zxing::ArrayRef<char> getMatrix() const.
    Note que tu as défini des fonctions similaires mais pas les fonctions exactes nécessaires.

    La seconde indique que ton constructeur BufferBitmapSource::BufferBitmapSource doit indiquer comment construire sa base zxing::LuminanceSource. Comme tu n'as pas fourni cette info, il essaie de construire LuminanceSource par défaut mais ça n'est pas possible.
    Il t'indique que le constructeur de LuminanceSource a besoin de 2 paramètres de type int et donc de faire par exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    BufferBitmapSource::BufferBitmapSource(int inWidth, int inHeight, unsigned char * inBuffer) 
       : zxing::LuminanceSource( inWidth , inHeight )
    {
    	width = inWidth; 
    	height = inHeight; 
    	buffer = inBuffer; 
    }

  3. #3
    Membre très actif
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    427
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 427
    Par défaut
    merci de l'aide

    j'ai encore une erreur, j'ai tenté de modifier dans "BufferBitmapSource.cpp"

    Code : 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
    //unsigned char * BufferBitmapSource::getRow(int y, unsigned char * row)
    ArrayRef<char> BufferBitmapSource::getRow(int y, ArrayRef<char> row)
    {
    	if (y < 0 || y >= height) 
    	{
    		fprintf(stderr, "ERROR, attempted to read row %d of a %d height image.\n", y, height); 
    		return NULL; 
    	}
    	// WARNING: NO ERROR CHECKING! You will want to add some in your code. 
    	if (row == NULL) row = new unsigned char[width]; 
    	for (int x = 0; x < width; x ++)
    	{
    		row[x] = buffer[y*width+x]; 
    	}
    	return row; 
    }
     
    //unsigned char * BufferBitmapSource::getMatrix()
    ArrayRef<char> BufferBitmapSource::getMatrix()
    {
    	return buffer; 
    }
    mais j'ai cette erreur

    BufferBitmapSource.h:20: error: candidate is: virtual zxing::ArrayRef<char> qrviddec::BufferBitmapSource::getRow(int, zxing::ArrayRef<char>) const
    cc1plus: warnings being treated as errors
    BufferBitmapSource.cpp: In member function 'zxing::ArrayRef<char> qrviddec::BufferBitmapSource::getRow(int, zxing::ArrayRef<char>)':
    BufferBitmapSource.cpp:41: warning: NULL used in arithmetic
    BufferBitmapSource.cpp:41: error: no match for 'operator=' in 'row = (zxing::ArrayRef<char>*)(((zxing::ArrayRef<char> (*)[((unsigned int)((qrviddec::BufferBitmapSource*)this)->qrviddec::BufferBitmapSource::width)])operator new [](((((unsigned int)((qrviddec::BufferBitmapSource*)this)->qrviddec::BufferBitmapSource::width) * 12u) + 4u))), (((*((<anonymous> + 4u) - 4u)) <unknown operator> ((unsigned int)((qrviddec::BufferBitmapSource*)this)->qrviddec::BufferBitmapSource::width)), ((*(zxing::ArrayRef<char> (*)[((unsigned int)((qrviddec::BufferBitmapSource*)this)->qrviddec::BufferBitmapSource::width)])({...})), <anonymous>)))'
    zxing/common/Array.h:143: note: candidates are: zxing::ArrayRef<T>& zxing::ArrayRef<T>::operator=(const zxing::ArrayRef<T>&) [with T = char]
    zxing/common/Array.h:147: note: zxing::ArrayRef<T>& zxing::ArrayRef<T>::operator=(zxing::Array<T>*) [with T = char]
    BufferBitmapSource.cpp: At global scope:
    BufferBitmapSource.cpp:50: error: prototype for 'zxing::ArrayRef<char> qrviddec::BufferBitmapSource::getMatrix()' does not match any in class 'qrviddec::BufferBitmapSource'
    BufferBitmapSource.h:21: error: candidate is: virtual zxing::ArrayRef<char> qrviddec::BufferBitmapSource::getMatrix() const
    BufferBitmapSource.cpp: In member function 'zxing::ArrayRef<char> qrviddec::BufferBitmapSource::getMatrix()':
    BufferBitmapSource.cpp:52: error: conversion from 'unsigned char*' to non-scalar type 'zxing::ArrayRef<char>' requested

  4. #4
    Expert confirmé
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 599
    Par défaut
    Il manque const à la fin des lignes 2 et 19.

  5. #5
    Membre très actif
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    427
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 427
    Par défaut
    merci, maintenant j'ai cette erreur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    /cckdf.o: error: undefined reference to '_libiconv_close'
    /cckdf.o: error: undefined reference to '_libiconv'
    /cckdf.o: error: undefined reference to '_libiconv_open'

  6. #6
    Membre très actif
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    427
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 427
    Par défaut
    ça fonctionne, merci pour ton aide.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Type mismatch: cannot convert from Object&Comparable<?>&Serializable to String
    Par oumaimaKati dans le forum Développement de jobs
    Réponses: 4
    Dernier message: 06/11/2017, 16h15
  2. Type mismatch: cannot convert from Object&Comparable<?>&Serializable to String
    Par dihonore dans le forum Développement de jobs
    Réponses: 2
    Dernier message: 14/10/2016, 14h44
  3. [2008R2] Error: INSERT failed because the following SET options have incorrect settings
    Par lepotier dans le forum Développement
    Réponses: 5
    Dernier message: 09/06/2015, 07h39
  4. Réponses: 6
    Dernier message: 18/05/2011, 18h15
  5. Allocation pointeur (pointeur dans un type)
    Par tyler007 dans le forum Fortran
    Réponses: 11
    Dernier message: 01/06/2007, 14h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo