为什么会出现错误C2143语法错误:缺少';'在“ *”之前?

时间:2018-10-21 18:47:48

标签: c++

我收到以下错误:

  

严重性代码描述项目文件行抑制状态   错误C2143语法错误:缺少';'在“ *”手电筒之前d:\ flashlight \ orbslam3 \ examples \ monocular \ flashlight.hpp 36

     

严重性代码描述项目文件行抑制状态   错误C4430缺少类型说明符-假定为int。注意:C ++不会   支持   default-int手电筒d:\ flashlight \ orbslam3 \ examples \ monocular \ flashlight.hpp 36

     

严重性代码描述项目文件行抑制状态   错误C2238之前的意外令牌   ';' d:\ flashlight \ orbslam3 \ examples \ monocular \ flashlight.hpp 36

这是我的头文件flashlight.hpp

#ifndef FLASHLIGHT_H
#define FLASHLIGHT_H

#include <cstdlib>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/locks.hpp>

#include "orbslam3.hpp"

using boost::asio::ip::udp;

class Flashlight {

    public:

        Flashlight(boost::asio::io_service& io_service, short port) : io_service_(io_service), socket_(io_service, udp::endpoint(udp::v4(), port)) {
            // start receiving udp data
            socket_.async_receive_from(
                boost::asio::buffer(data_recv_, max_length), sender_endpoint_, boost::bind(&Flashlight::handle_receive_from, this,
                    boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
            );
        }

        void start_loop();
        void send_beacon();

        void handle_send_to(const boost::system::error_code& error, size_t bytes_sent);
        void handle_receive_from(const boost::system::error_code& error, size_t bytes_recvd);


    private:

        ORBSLAM3 *orbslam;          // <= ERRORS APPEAR HERE (Line 36)

        boost::asio::io_service& io_service_;
        udp::socket socket_;
        udp::endpoint sender_endpoint_;
        enum { max_length = 1024 };
        char data_recv_[max_length];
        char data_sent_[max_length];

};

#endif

这是我的实现文件flashlight.cpp

#include "flashlight.hpp"

using namespace std;                // for atoi()
using boost::asio::ip::udp;

int main(int argc, char* argv[]) {
    try {
        const uint16_t udp_port = 19630;
        // thread to run network services asynchronously
        boost::thread_group tgroup;
        // start udp network endpoint
        boost::asio::io_service io_service;
        // instantiate flashlight class
        Flashlight flashlight(io_service, udp_port);
        // run network entities in own thread
        tgroup.create_thread(boost::bind(&boost::asio::io_service::run, &io_service));
        cout << "Server running on UDP port " << udp_port << endl;
        // start main loop
        flashlight.start_loop();
        // shutdown network threads
        tgroup.join_all();
    } catch(exception& e) {
        cerr << "Exception: " << e.what() << "\n";
    }
    return 0;
}

void Flashlight::start_loop() {
    string sensor_type = "stereo";
    string vocab_path = "D:\\Flashlight\\ORBSLAM3\\Examples\\Monocular\\Release\\ORBVoc.bin";
    string settings_path = "D:\\Flashlight\\ORBSLAM3\\Examples\\Monocular\\Release\\stereo_2_8_mm_640_480.yaml";
    //const string settings_path = "../"+sensor_type+"_"+lens_type+"_mm_"+to_string(cam_width)+"_"+to_string(cam_height)+".yaml";
    uint16_t cam_width = 640;
    uint16_t cam_height = 480;
    // orb slam system initialization
    this->orbslam = new ORBSLAM3(sensor_type, vocab_path, settings_path, cam_width, cam_height);
    // mainloop
    char key;
    while((key = std::cin.get()) != 27) {
        this->orbslam->loop();
    }
    // shutdown orbslam threads
    this->orbslam->shutdown();
    // save camera trajectory
    //orbslam->SaveTrajectoryTUM("CameraTrajectory.txt");
}

void Flashlight::send_beacon() {
    while(true) {
        boost::posix_time::seconds workTime(1);
        // send_async(beacon)
        std::cout << "Beacon signal sent ..." << std::endl;
        boost::this_thread::sleep(workTime);
    }
}

void Flashlight::handle_receive_from(const boost::system::error_code& error, size_t bytes_recv) {
    if(!error && bytes_recv > 0) {
        std::cout << "UDP received: "; for(int i=0; i<bytes_recv; i++) std::cout << (int)data_recv_[i] << ", "; std::cout << std::endl;
        // start listening again
        socket_.async_receive_from(
            boost::asio::buffer(data_recv_, max_length), sender_endpoint_, boost::bind(&Flashlight::handle_receive_from, this,
                boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
        );
    }
}

void Flashlight::handle_send_to(const boost::system::error_code& error, size_t bytes_sent) {
    socket_.async_send_to(
        boost::asio::buffer(data_sent_, bytes_sent), sender_endpoint_, boost::bind(&Flashlight::handle_send_to, this,
            boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
    );
}

我找不到我想念的东西。有想法吗?


更新:添加了orbslam3.hpporbslam3.cpp

#ifndef ORBSLAM3_H
#define ORBSLAM3_H

#include <algorithm>
#include <fstream>
#include <chrono>
#include <opencv2/core/core.hpp>

#include <cstdlib>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/locks.hpp>

#include "flashlight.hpp"

// ==============================
// IMPORTANT: Don NOT move up the 
// ========== following include !
#include <System.h>

class ORBSLAM3 {

    public:

        ORBSLAM3(string &sensor_type, string &vocab_path, string &settings_path, uint16_t cam_width, uint16_t cam_height);

        int loop();

        void pause();
        void resume();
        void reset();

        void setMode(bool mapping);     // false := localization only, true := localization+mapping

        void saveMap();
        void loadMap();

        void shutdown();


    private:

        string sensor_type;             // types = {"mono", "stereo", "rgbd")
        string vocab_path;              // path to the vocabulary (*.bin/*.txt)
        string settings_path;           // patch to the settings file (*.yaml)
        uint16_t cam_width;             // horizontal camera resolution
        uint16_t cam_height;            // vertical camera resolution

        ORB_SLAM2::System *slam;        // main orbslam system

        cv::VideoCapture *cap1;         // first camera capture devices
        cv::VideoCapture *cap2;         // second camera capture devices

        cv::Mat img_left, img_right;    // stereo images captured
        cv::Mat tcw;                    // pose output information

};

#endif

实施文件orbslam3.cpp

#include "orbslam3.hpp"

using namespace std;

ORBSLAM3::ORBSLAM3(string &sensor_type, string &vocab_path, string &settings_path, uint16_t cam_width, uint16_t cam_height) {
    // assign arguments to local fields
    this->sensor_type = sensor_type;
    this->vocab_path = vocab_path;
    this->settings_path = settings_path;
    this->cam_width = cam_width;
    this->cam_height = cam_height;
    // initialize ORBSLAM system
    if(sensor_type.compare("mono")==0) {
        this->slam = new ORB_SLAM2::System(vocab_path, settings_path, ORB_SLAM2::System::MONOCULAR, true, true);
    } else if(sensor_type.compare("stereo")==0) {
        this->slam = new ORB_SLAM2::System(vocab_path, settings_path, ORB_SLAM2::System::STEREO, true, true);
    } else if(sensor_type.compare("rgbd")==0) {
        this->slam = new ORB_SLAM2::System(vocab_path, settings_path, ORB_SLAM2::System::RGBD, true, true);
    } else {
        std::cout << "ERROR: Unknown sensor type: " << sensor_type << std::endl;
    }
    // initialize cameras
    cap1 = new cv::VideoCapture(0);
    cap2 = new cv::VideoCapture(1);
    // set camera resolutions
    cap1->set(CV_CAP_PROP_FRAME_WIDTH, cam_width);
    cap1->set(CV_CAP_PROP_FRAME_HEIGHT, cam_height);
    cap2->set(CV_CAP_PROP_FRAME_WIDTH, cam_width);
    cap2->set(CV_CAP_PROP_FRAME_HEIGHT, cam_height);
}

int ORBSLAM3::loop() {
    // capture left and right images
    cap1->read(img_right);
    cap2->read(img_left);
    // convert to b/w
    //cv::cvtColor(imRight, imRight, CV_BGR2GRAY);
    //cv::cvtColor(imLeft, imLeft, CV_BGR2GRAY);
    // check image validity
    if(img_left.empty()) {
        cerr << endl << "Failed to capture left image." << endl;
        return 1;
    }
    if(img_right.empty()) {
        cerr << endl << "Failed to capture right image." << endl;
        return 1;
    }
    // time
    __int64 cnow = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
    // pass the images to the SLAM system
    tcw = slam->TrackStereo(img_left, img_right, cnow / 1000.0);
    // visualize stereo images
    cv::imshow("Left Image", img_left);
    cv::imshow("Right Image", img_right);
}

void ORBSLAM3::pause() {

}

void ORBSLAM3::resume() {

}

void ORBSLAM3::reset() {

}

void ORBSLAM3::setMode(bool mapping) {

}

void ORBSLAM3::saveMap() {

}

void ORBSLAM3::loadMap() {

}

void ORBSLAM3::shutdown() {
    slam->Shutdown();
    cap1->release();
    cap2->release();
}

1 个答案:

答案 0 :(得分:2)

好像您具有循环依赖关系。 解决该问题,它应该可以工作。

flashlight.hpp

// Remove this line. 
//    #include "orbslam3.hpp"
// Add a forward declaration.
// Unless you need the full declaration you should not be including the header file
// Prefer to use forward declarations when you are just using a pointer.
class ORBSLAM3;

flashlight.cpp

#include "flashlight.hpp"
// Add this line.
// You will probably need the actual definition if you use it in the code.
#include "orbslam3.hpp"

orbslam3.hpp

// Does not even look you need this in the header file.
// Remove headers you don't need.
// #include "flashlight.hpp"