标签: class-template

C++ - 定义类模板(头文件/源文件)

我想在voreen中创建一个处理器(就像这个.cpp | .h)移植这个OTB-Application:

http://hg.orfeo-toolbox.org/OTB/file/ca4366bb972e/Applications/Segmentation/otbSegmentation.cxx

我已将几乎所有参数编码为属性等,但..

如果你看一下376,你会看到一个类模板FloatVectorImageType :: SizeType,一个typedef类型.

我不熟悉c ++模板所以我的第一个问题是我应该把这个模板的实现放在处理器的.cpp或.h文件中?以在C++教程和其他处理器的例子,如一个简要回顾一下上面一个,我弄清楚我要申报在报头中的模板和在.cpp定义它.

问题是编译器不允许我在.cpp中定义typedef类型的模板类.typedef不被认可..

那么,有人能指出我正确的方向吗?

segmentationprocessor.h

#ifndef OTBSEGMENTATIONAPPLICATION_H
#define OTBSEGMENTATIONAPPLICATION_H

#include "otbVectorImage.h"
#include "modules/otb/ports/otbimageport.h"
#include "modules/otb/ports/otbvectorimageport.h"
#include "voreen/core/properties/boolproperty.h"

//..more includes here

namespace voreen {

class OTBSegmentationApplication : public OTBImageFilterProcessor
{
public:
    OTBSegmentationApplication();

    virtual ~OTBSegmentationApplication();

    virtual Processor* create() const;

    virtual std::string getCategory() const { return "Applications"; }
    virtual std::string getClassName() const { return "Segmentation Application"; }
    virtual CodeState getCodeState() const { return CODE_STATE_EXPERIMENTAL;}//STABLE, TESTING, EXPERIMENTAL

    virtual std::string getProcessorInfo() …
Run Code Online (Sandbox Code Playgroud)

c++ porting header-files class-template

1
推荐指数
1
解决办法
1万
查看次数

关于评估is_array模板类的困惑

考虑以下程序(请参阅此处的实时演示.)

#include <iostream>
#include <type_traits>
int main()
{
    struct T{ virtual void foo()=0;};
    std::cout<<std::boolalpha;
    std::cout<<std::is_array<int[3]>::value<<'\n';
    std::cout<<std::is_array<T>::value<<'\n';
    std::cout<<std::is_array<T1[2]>::value<<'\n';
    std::cout<<std::is_array<T[3]>::value<<'\n'; // why uncommenting this line causes compile time error?
}
Run Code Online (Sandbox Code Playgroud)

我知道创建抽象类的对象是不可能的.这里T是抽象的,因此不可能创建struct T的对象.但请考虑以下语句

std::cout<<std::is_array<T[3]>::value<<'\n';
Run Code Online (Sandbox Code Playgroud)

为什么它会给我一个错误?该语句仅检查给定类型是否为数组.是否意味着如果T是静态成员的阵列&值value的计算结果为true然后对象数组将被创建?但是,为什么需要在这里创建数组呢?什么是创建数组的需要如果我不能使用该数组?这不仅仅是记忆的浪费吗?

那么为什么以下语句不会给出任何编译器错误?

std::cout<<std::is_array<T>::value<<'\n';
Run Code Online (Sandbox Code Playgroud)

我在这里理解错了什么?请帮我.

c++ evaluation abstract-class object class-template

1
推荐指数
1
解决办法
140
查看次数

C++ - 使用类模板时出错

在main.cpp文件中...

#include "pqueue.h"

struct nodeT;

struct coordT {
    double x, y;
};

struct arcT {
    nodeT *start, *end;
    double weight;
};

int arcComp(arcT *arg0, arcT *arg1){
    if(arg0->weight == arg1->weight)
        return 0;
    else if(arg0->weight > arg1->weight)
        return 1;
    return -1;
}

struct nodeT {
    coordT* coordinates;
    PQueue<arcT *> outgoing_arcs(arcComp); // error on this line
};
Run Code Online (Sandbox Code Playgroud)

在文件pqueue.h中...

#ifndef _pqueue_h
#define _pqueue_h

template <typename ElemType>
class PQueue 
{
private:
    typedef int (*CallbackFunc)(ElemType, ElemType);
    CallbackFunc CmpFunc;

public:
    PQueue(CallbackFunc Cmp);
    ~PQueue();  
};

#include "pqueue.cpp"
#endif …
Run Code Online (Sandbox Code Playgroud)

c++ class-template

0
推荐指数
1
解决办法
832
查看次数

范围分辨率而不是.模板类参数的运算符

下面给出的代码成功编译:

template <typename T, T nontype_param>
class C;

class X {
public:

  int n;
  };

int main()
{

    C<int X::*, &X::n>* c; //Here 

    return 1;
}
Run Code Online (Sandbox Code Playgroud)

Scope解析器操作符如何在此处工作而不是. operator?我们是否可以访问这样的非静态成员?

参考:C++模板完整指南,第8.3.3节非类型参数

c++ class-template

0
推荐指数
1
解决办法
272
查看次数