我收到了“字段不完整类型”的错误,但也不确定原因。有人可以帮忙吗?谢谢!
g++ -pipe -W -Wall -fopenmp -ggdb3 -DDEBUG -fno-omit-frame-pointer -c -o test.o ../../src/test.cc
In file included from ../../src/test.cc:50:
../../src/feature_haar.h:14: error: field ‘_count’ has incomplete type
test.cc
#include "feature_count.h"
#include "feature_random_counts.h"
#include "feature_corner.h"
#include "feature_haar.h" // line 50
feature_haar.h
#ifndef FEATURE_HAAR_H
#define FEATURE_HAAR_H
#include "misc.h"
#include "feature.h"
#include "vignette.h"
#include "feature_count.h"
#include <cassert>
class FeatureHaar: public Feature
{
public:
FeatureCount _count;// line 14
...
}
#endif
feature_count.h
#ifndef FEATURE_COUNT_H
#define FEATURE_COUNT_H
#include "misc.h"
#include "feature.h"
#include "random_rect.h"
//#include "feature_integral_img.h"
class FeatureCount: public Feature {
public:
RandomRect _rect;
char _type[buffer_size];
// This method returns an upper-caps string to identify the feature
const char *name() ;
FeatureCount();
FeatureCount( int width, int height, const char *type = "black-count", float WHRatio=-1, int roi_x=0, int roi_y=0, int roi_w=0, int roi_h=0 );
~FeatureCount();
// compute features from original data i.e. image
void compute(double *integral_image, double *feature);
// IO
void write_humanreadable(ostream *out);
void write(ostream *out);
void read(istream *in):
};
#endif
feature.h中
#ifndef FEATURE_H
#define FEATURE_H
#include "misc.h"
#include "vignette.h"
class Feature {// generate the feature from the original data of an example, not responsible for holding the feature.
public:
int _dim;
// We need a virtual destructor since there are virtual methods
virtual ~Feature();
// This method returns an upper-caps string to identify the feature
virtual const char *name() = 0;
// write the data into files
static void write_matrix_data(double ** features, int *labels, int nb_examples, int dim, const char * filename);
static void write_index_data(double ** features,int *labels, int nb_examples, int dim, const char * filename);
static void write_compact_data(double ** features, int *labels, int nb_examples, int dim, const char * filename);
// compute features from original data i.e. image
virtual void compute(Vignette *vignette, double * feature); // this function/class not responsible for allocating/deallocation memory for array feature
virtual void compute(double *integral_image, double *feature);
// feature preprocessing
// scaling each feature s.t. its sample max = 1 and min = 0
static void scale_features(double *Data, int dim, double *scales_min, double *scales_max);
static void compute_linear_scale(double **Data, int size, int dim, double *scales_min, double *scales_max);
// standardize each feature s.t. its sample mean = 0 and sample standard deviation = 1
static void standardize_features(double *Data, int dim, double *mean, double *std);
static void compute_standardization(double **Data, int size, int dim, double *mean, double *std);
};
#endif
答案 0 :(得分:10)
感谢所有帮助我的人。这是我的坏事。 FeatureCount的定义不对。其成员
void read(istream *in):
应以“;”结尾不是“:”。
如此难以找到如此小的错字?
答案 1 :(得分:10)
如果两个类互相使用,则必须有一个指针,因为在收到完整声明之前,不能使用该类。
例如:
<强> b.h 强>
#ifndef _B
#define _B
#include "A.h"
class B
{
public:
B();
A a;
};
#endif
<强> A.H 强>
#ifndef _A
#define _A
class B;
class A
{
public:
A();
B b;
};
#endif
有两个问题:
无法编译A类,因为没有完整声明就使用了B.添加#include“b.h”将不起作用,因为: a.h - 包括“b.h” b.h - 包括“a.h”,自保护后没有声明,因此b级不能创建'A a;'
即使它编译了,A也会创建B,然后B创建A;然后A创造B;然后B创建A直到它崩溃。
这将有效:
<强> B.h 强>
#ifndef _B
#define _B
#include <iostream>
#include "A.h"
class B
{
public:
B() {}
A a;
void hi() {std::cout << "hi" << std::endl;}
};
#endif
<强> A.H 强>
#ifndef _A
#define _A
class B;
class A
{
public:
A();
void set(B *p);
void sayHi();
private:
B *b;
};
#endif
<强> A.cpp 强>
#include "A.h"
#include "B.h"
A::A() : b(0) {}
void A::set(B *p) {b=p;}
void A::sayHi() { if(b) b->hi(); }
int main()
{
A a;
B b;
a.set(&b);
a.sayHi();
return 0;
}
g ++ -g -oworks A.cpp
作品
喜
答案 2 :(得分:2)
没有看到所有代码,最可能的问题是Feature_Haar
的继承链中的一个类只是一个前向声明。
http://msdn.microsoft.com/en-us/library/200xfxh6.aspx
仍然看不到可能导致此事的任何事情。开始浏览所有包含文件并查找这样的前向声明:
struct SomeStruct; class Someclass;
答案 3 :(得分:2)
看起来它可能是RandomRect。
答案 4 :(得分:1)
因为它显然有不完整的类型。我们需要看到FeatureCount
的定义来说明为什么它是一个不完整的类型。