2011-08-18 3 views
2

Windows 용 Visual Studio에서 Opengazer (오픈 소스 시선 추적기) 코드를 컴파일하려고합니다. 코드는 원래 Linux 용으로 작성되었으므로 cmake로 컴파일해야합니다.무언가를 이해하지 않고 .h 파일을 컴파일하려고합니다.

어쨋거나 일부 파일을 컴파일 할 수 없습니다.

Containers.h :

#pragma once 

#define xforeachactive(iter,container) \ 
    for(typeof(container.begin()) iter = container.begin(); \ 
    iter != container.end(); iter++)   \ 
    if ((*iter)->parent == this) 


template <class ParentType, class ChildType> class Container; 

template <class ParentType, class ChildType> 
class Containee { 
protected: 
    void detach() { parent = 0; } 
public: 
    ParentType *parent;  /* set to null to request removal */ 
    Containee(): parent(0) {} 
    virtual ~Containee() {} 
}; 

template <class ParentType, class ChildType>   
class Container { 
    typedef ChildType *ChildPtr; 
    static bool isFinished(const ChildPtr &object) { 
    return !(object && object->parent); 
    } 
protected: 
    std::vector<ChildPtr> objects; 

    void removeFinished() { 
    objects.erase(remove_if(objects.begin(), objects.end(), isFinished), 
       objects.end()); 
    } 

public: 
    void clear() { 
    xforeachactive(iter, objects) 
     (*iter)->parent = 0; 
    removeFinished(); 
    } 


    static void addchild(ParentType *parent, const ChildPtr &child) { 
    parent->objects.push_back(child); 
    child->parent = parent; 
    parent->removeFinished(); 
    } 

    virtual ~Container() { 
    clear(); 
    } 
}; 

template <class ParentPtr, class ChildPtr> 
class ProcessContainer: public Container<ParentPtr, ChildPtr> { 
public: 
    virtual void process() { 
    xforeachactive(iter, this->objects) 
     (*iter)->process(); 
    this->removeFinished(); 
    } 
    virtual ~ProcessContainer() {}; 
}; 

BTW Containers.cpp 코드는 위의 클래스를 사용하여 빈

광고입니다 :

컴파일되지 않습니다 코드는 다음입니다

#pragma once 

class FrameProcessing; 

class FrameFunction: 
public Containee<FrameProcessing, FrameFunction> 
{ 
    const int &frameno; 
    int startframe; 
protected: 
    int getFrame() { return frameno - startframe; } 
public: 
    FrameFunction(const int &frameno): frameno(frameno), startframe(frameno) {} 
    virtual void process()=0; 
    virtual ~FrameFunction(); 
}; 

class FrameProcessing: 
public ProcessContainer<FrameProcessing,FrameFunction> {}; 

class MovingTarget: public FrameFunction { 
    WindowPointer *pointer; 
public: 
    MovingTarget(const int &frameno, 
     const vector<Point>& points, 
     WindowPointer *&pointer, 
     int dwelltime=20); 
    virtual ~MovingTarget(); 
    virtual void process(); 
protected: 
    vector<Point> points; 
    const int dwelltime; 
    int getPointNo(); 
    int getPointFrame(); 
    bool active(); 
}; 

class CalibrationHandler 
{ 
public: 
    CalibrationHandler(void); 
    ~CalibrationHandler(void); 
}; 

오류는 다음과 같습니다.

visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2146: syntax error : missing ';' before identifier 'iter' 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2065: 'iter' : undeclared identifier 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2065: 'iter' : undeclared identifier 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2146: syntax error : missing ')' before identifier 'iter' 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2059: syntax error : ';' 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2065: 'iter' : undeclared identifier 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2059: syntax error : ')' 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2143: syntax error : missing ';' before 'if' 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2065: 'iter' : undeclared identifier 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(58) : error C2227: left of '->parent' must point to class/struct/union/generic type 
     type is ''unknown-type'' 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(59) : error C2065: 'iter' : undeclared identifier 
visual studio 2008\projects\eyemouse\eyemouse\containers.h(59) : error C2227: left of '->process' must point to class/struct/union/generic type 
     type is ''unknown-type'' 

나는 오류가 발생하는 이유를 알고 있습니다. 'iter'가 정의되지 않았습니다. 어쨌든, 이것은 내 코드가 아니며 작동해야합니다. define 요소를 복사하여 함수에 전달하려고했지만 여전히 동일한 오류가 발생합니다. 나는 이것으로 붙어있어 몇 시간 동안 그것을 해결하는 것을 시도하고, 그러나 그것을 일하기 위하여하기 위하여 무엇을 이해할 수 없다.

정말 도움이 될 것입니다.

+0

어떤 VS 버전을 사용하십니까? 실제로'typeof'를 지원합니까? – pmr

답변

3

typeof은 gcc 확장이며 C++ 0x decltype과 동일합니다. 실제로 지원하는 VS 버전은 없습니다.

C++ 0x 및 decltype을 사용하거나 자체주의 사항과 함께 제공되는 Boost.TypeOf을 사용해야합니다.

변경이에 매크로 :

#include <boost/typeof/typeof.hpp> 

#define xforeachactive(iter,container) \ 
    for(BOOST_TYPEOF(container.begin()) iter = container.begin(); \ 
    iter != container.end(); iter++)   \ 
    if ((*iter)->parent == this) 

이 명확하다고 생각하는 경우도 BOOST_AUTO을 사용할 수 있습니다.

+0

답변 해 주셔서 감사합니다. VS가 typeof를 지원하지 않는다는 것을 이해합니다. Boost.Typeof를 포함 시키려고했지만 여전히 같은 오류가 발생합니다. 'iter'가 아직 정의되지 않았기 때문에 컴파일 방법을 이해할 수 없습니다. – Frank

+0

@Frank이 문제를 해결할 코드를 추가했습니다. 불행히도 나는 이것을 시험 할 수 없다. – pmr

+0

도와 주셔서 감사합니다. 그것을 고칠했지만 다른 오류가 지금 직면하고있어. 나는 지금 오류를 게시했다. – Frank

관련 문제