0

我有一个 QRCode 签名类,我希望放置日志记录语句,我从构造函数部分开始:

QRCodeSignature::QRCodeSignature(std::vector<WacomType::PEN>* theSigpoints, int theInterval, int theVersion) : sigpoints(theSigpoints), interval(theInterval), version(theVersion) {
Logging::log(QRCodeSignature::logger, Logging::Entry, QRCodeSignature::CLASSNAME, "QRCodeSignature");

我在 QRCodeSignature.cpp 中有以下内容

  #include "QRCodeSignature.h"
  #include <iostream>
  #include <cstdlib>
  #include <stdio.h>
  #include <stdlib.h>
  #include <math.h>

在 QRCodeSignature.hi 中有以下类作为 QRCodeSignature

  a constructor
  a virtual destructor
  private:
  static const std::string CLASSNAME;
  static Logging::Logger* logger;

在 QRCodeSignature.cpp 我有

 const std::string CLASSNAME = "QRCodeSignature";
 Logging::logger* QRCodeSignature::logger = NULL;

我构建这个项目时的错误[发布]

 build/Release/MinGW_1-Windows/QRCodeSignature.o: In function `QRCodeSignature':
 C:\repos\impression\trunk\ProsenseSign/QRCodeSignature.cpp:13: undefined reference to `QRCodeSignature::CLASSNAME'
 collect2: ld returned 1 exit status
 make[2]: *** [dist/Release/MinGW_1-Windows/impression.api] Error 1
 make[1]: *** [.build-conf] Error 2
 make: *** [.build-impl] Error 2
4

1 回答 1

0

你应该使用

const std::string QRCodeSignature::CLASSNAME = "QRCodeSignature";

代替

const std::string CLASSNAME = "QRCodeSignature";

因为第二个不是static-member类的初始化。

于 2012-08-24T05:37:23.143 回答