2011-03-18 88 views
0

我回来了这个PCNN代码从一本教科书。
我在变量F,L,U,T和Y中得到了关联
的行中pcn2d.cc中的“无匹配函数调用”错误。以下是类文件,代码文件和编译器日志:“呼叫没有匹配的功能”HAS我BAFFLED

rimage.h

// 
    // rimage.h 
    // 
    // 
    // Jason M. Kinser 
    // 15 October 1995 
    // rimage.h 
    // an image of real elements 
    // 1 April 1996 - added histogram 
    // 15 April 1996 - addeed hgradientbox 
    // 27 June 1996 - a dded /= rimage 
    // 7 July 1996 - added/rimage, Smooth 
    // 
     #include "matrix.h" 
     #ifndef RIMAGE  
     #define RIMAGE 
     typedef unsigned short word;  
     typedef unsigned long dword; 

     class rimage : public matrix { 
    public: 
     rimage(void); 
     rimage(int, int); 
     rimage(rimage &); 
     rimage & operator=(const matrix & A); 
     rimage & operator=(const rimage & A); 
     rimage & operator/=(int); 
    // Math 
     rimage operator+(float); 
     rimage operator+(const rimage &); 
     rimage operator*(const rimage &); // element 
     rimage operator*(float); 
     friend rimage operator+(float, const rimage &); 
     friend rimage operator*(float, const rimage &); 
     rimage Convolve(rimage &); 
    // Image conversions 
     void UpsideDown(void); 
    // Input/Output 
     void SaveTarga(char *); 
    } ; 
    #endif 

pcnn2d.h

// 
    // pcnn2d.h 
    // A 2D Pulse-Coupled Neural Network 
    // Jason Kinser 
    // 15 April 1996 
    // 
    #include "rimage.h " 
    class PCNN { 
    int vert, horz; 
    rimage Quantized (void); 
    public: 
     rimage F, L, U, T, Y, K; 
     float af, al, at, beta, vf, vl, vt; 
     PCNN(int, int);  // The two dimensions 
     PCNN(const PCNN &); // copy 
     ~PCNN(void); 
    int KernVert(void) const; 
    int KernHorz(void) const; 
    void StdK(void); 
    int Iterate (rimage &); 
    int FastIterate(rimage &); // uses fast linking 
    void Clear(void); 
    void Save(char *); 
    void Load(char *); 
    }; 

pcnn2d.cc

// 
    // pcnn2d.cc 
    // The Pulse-Coupled Neural Network 
    // 
    // Jason Kinser 
    // 15 April 1996 

    #include <math.h> 
    #include <stdlib.h> 
    #include "pcnn2d.h" 

    PCNN::PCNN(int V, int H) 
    { 
     vert = V; horz = H; 
     F.New(V, H); 
     L.New(V, H); 
     U.New(V, H); 
     T.New(V, H); 
     Y.New(V, H); 
     K.New(5, 5); 
     af = 10.0; al = 1.0; at = 5.0; 
     beta = 0.1; 
     vf = 0.5; vl = 0.5; vt = 20.0; 
     StdK(); 
    } 

    PCNN::PCNN(const PCNN & P) 
    { 
     vert = P.vert; horz = P.horz; 
     F.New(vert, horz); 
     L.New(vert, horz); 
     U.New(vert, horz); 
     T.New(vert, horz); 
     Y.New(vert, horz); 
     K.New(P.KernVert (), P.KernHorz()); 
     F = P.F; L = P.L;  U = P.U; 
     T = P.T; Y = P.Y;  K = P.K; 
     af = P.af; al = P.al; at = P.at; 
     beta = P.beta; 
     vf = P.vf; vl = P.vl; vt = P.vt; 
    } 
    PCNN::~PCNN(void) 
    { 
     F.Dispose(); L.Dispose(); U.Dispose(); 
     T.Dispose(); Y.Dispose(); K.Dispose(); 
    } 

    int PCNN::KernVert(void) const 
    // returns the vertical dimension of the kernel 
    { return K.Vert(); } 

    int PCNN::KernHorz(void) const 
    { return K.Horz(); } 

    void PCNN::StdK(void) 
    { int i, j, kv, kh; float val; 
     kv = K.Vert(); kh = K.Horz(); 
     for (i=0; i<kv; i++) for (j=0; j<kh; j++) 
     { 
      val = hypot(i-kv/2, j-kh/2); 
      if(val != 0.0) val = 1.0/val; 
      else val = 1.0; 
      K[i][j] = val; 
     } 
    } 
    rimage PCNN::Quantized (void) 
    { 
     int i,j; rimage ans(vert, horz); 
     rimage work(vert, horz), k(3,3); 
     k.Clear(1.0); 
     work = Y.Convolve(k);  //ERROR LINE 74 
    for (i=0; i<work.Vert(); i++) for (j=0; j<work.Horz(); j++) 
     if(work[i][j] > 1.0) ans[i][j] = 1.0; 
     else ans [i][j] = 0.0; 
    return ans; 
    } 
    int PCNN::Iterate(rimage & A) 
    { 
     rimage work(F.Vert() , F.Horz()); 
     work = Y.Convolve(K);    //ERROR LINE 83 
     F = exp(-1.0/af) * F + vf * work + A; //ERROR LINE 84 
     L = exp(-1.0/al) * L + vl* work; //ERROR LINE 85 
     U = F * (1.0 + beta * L);   //ERROR LINE 86 
     for(int i=0; i<vert; i++) for (int j = 0; j<horz; j++) 
      if(U[i][j] > T[i][j]) 
      Y[i][j] = 1.0; 
      else 
      Y[i][j] = 0.0; 
     T = exp (-1.0/at) * T + vt * Y; //ERROR LINE 92 
     return int(Y.Sum()); 
    } 
    int PCNN::FastIterate(rimage & A) 
    { 
     rimage work (F.Vert(), F.Horz()), Q (F. Vert() , F.Horz()); 
     int n=0; 
     if(vf != 0) work = Y.Convolve(K); //ERROR LINE 99 
     F = exp(- 1.0/af) * F + vf * work + A; //ERROR LINE 100 
     Y.Clear(); 
     do { 
      Q = Y; n++; 
      L = Quantized();  //ERROR LINE 104 
      U = F * (1.0 + beta * L); //ERROR LINE 105 
      for(int i=0; i<vert; i++) for(int j=0; j<horz; j++)     
      if(U[i][j] > T[i][j]) 
      Y[i][j] = 1.0; 
     } 
     while((Q + Y).Sum() > 1 && n < 5); 
     T = exp(-1.0/at) * T + vt * Y; //ERROR LINE 111 
     return int (Y.Sum()); 
    } 

编译器日志:

g++.exe -c "PCNN Code/pcnn2d.c" -o 
"PCNN Code/pcnn2d.o" -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  
-I"C:/Dev-Cpp/include/c++/3.4.2/backward"  
-I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  
-I"C:/Dev-Cpp/include/c++/3.4.2" 
-I"C:/Dev-Cpp/include"  


In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, 
       from PCNN Code/vector.h:9, 
       from PCNN Code/matrix.h:10, 
       from PCNN Code/rimage.h :15, 
       from PCNN Code/pcnn2d.h:8, 
       from PCNN Code/pcnn2d.c:12: 
C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: 
warning: #warning This file includes at least one deprecated or antiquated header. 
Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. 
PCNN Code/pcnn2d.c: In member function `rimage PCNN::Quantized()': 
PCNN Code/pcnn2d.c:74: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 

PCNN Code/pcnn2d.c: In member function `int PCNN::Iterate(rimage&)': 
PCNN Code/pcnn2d.c:83: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:84: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:84: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:85: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:85: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:86: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:86: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:86: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:92: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:92: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c: In member function `int PCNN::FastIterate(rimage&)': 
PCNN Code/pcnn2d.c:99: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:100: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:100: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:104: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:105: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:105: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:105: error: no matching function for call to `rimage::rimage(rimage)' 

PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:111: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 
PCNN Code/pcnn2d.c:111: error: no matching function for call to `rimage::rimage(rimage)' 
PCNN Code/rimage.h :27: note: candidates are: rimage::rimage(rimage&) 

make.exe: *** ["PCNN Code/pcnn2d.o"] Error 1 
Execution terminated 
+1

由于这是C++文件,文件扩展名不应该是'.cc'或'.cpp'吗? – Asha 2011-03-18 06:15:17

+1

您能删除所有成员函数的实现并只保留一个有错误的实现吗?这样很容易理解和解决。 – balki 2011-03-18 06:22:49

+0

采取的两点。这是我正在故意编写的文本书中的代码。我增加了超过必要的内容,以确保没有任何关键的东西被遗漏。我在论坛的帮助下解决了问题,我很高兴。 – databoy 2011-03-19 00:51:49

回答

2

它谈论不rimage::rimage(rimage&)通话完全匹配。这通常意味着您正试图从临时对象复制,如果已使用此复制构造函数,则该对象可能是rimage::rimage(const rimage&)

为什么不是?因为代码是15年前的,从此之前有一个C++标准?

+0

再次感谢你们。这解决了问题,并且我成功编译了项目 – databoy 2011-03-19 00:43:37

0

yup - 您的拷贝构造函数必须是rimage(const rimage& other) - 请注意额外的const

由于某种原因,ms的编译器支持将其作为扩展

与地方const,符合标准的编译器(标准)被允许创建/使用临时rimage情况下,除非有一个转换,并声明该构造explicit

解决方案:你将不得不

1)提供使用const修饰词并为它的参数

2)或明确创建一个非const rimage实例和传递的副本拷贝构造函数。

哪个更好/适用取决于实际的实施方式,以及在某些情况下,启用复印的成本/副作用。

+0

复制构造函数需要一个const是正确的,但这不是编译器扩展。该规范显式允许您编写一个通过非const引用接受其参数的副本构造函数。 – templatetypedef 2011-03-18 06:51:42

+0

谢谢,这解决了这个问题。我喜欢这个论坛!你们在正确答案的基础上是正确的。 – databoy 2011-03-19 00:46:10