简体   繁体   中英

pthread_create() "class not declared in the scope?

I have a class called pos... I am trying to poll a method from this class. I used pthread_create(pthread_t thread, pos::Pirnt_data,this);

I get an error that pos is not declared in the scope... I included the h file of pos but I don't understand. I think I am using a wrong format can somebody help me

#include "position.h"
#include "pthread.h"
#include "pos.h"
void position::tick(schedflags_t flags) 
{   
    if(pthread_create(&thread,NULL,pos::Print_data,this)!=0) {
        stringstream bad;
        bad << "OPIMex: Could not create listener thread: "
    }

this class position has method tick that runs every 1 second with the data. I am trying to poll a method Print data from the class pos but it gave me that error any ideas why ?

this is class pos.h

#ifndef POS_H_
#define POS_H_



#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <gps.h>
#include <string.h>
#include <pthread.h>
#include <string>
#include <vector>

#include <strings.h>
#include <math.h>


using namespace std;
namespace herpderp {
namespace modules {



int UBX_step =0;
long data;
int UBX_class;
int UBX_id=0;
int UBX_payload_length_hi;
int UBX_payload_length_lo;
int UBX_payload_counter =0;
int ck_a;
int ck_b;
int GPS_timer;
int fd;
unsigned int UBX_buffer[35];
int payload_data;
long lat=0;
long lon=0;
long alt_MSL=0;
long iTOW=0;
long alt=0; 
unsigned long LastMS;
int UBX_Read;
vector <float> v;
fstream myfile;

int Open_port(void);
int read_tofile();
long join_4_bytes( unsigned int Buffer[]);
void parse_ubx_gps(void);
void checksum(char ubx_data);
void Print_data();
int push_data_into_vector();
int decode_gps();
int Configure_gps();
int test();
int Close_NEMA();
int Open_UBX();

  }

} #endif //POS_H_

1) you can provide some code snippet/additional information to help you better.

2) If you are getting linkage error, check if you have linked with -lpthread library.

从pos.h看来,似乎没有叫做pos的类,您只需要调用函数名即可:

 if(pthread_create(&thread,NULL,Print_data,this)!=0) {

pthread_kill is not on pthread. . It is on signal.h

#include <signal.h>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM