コンパイルの基本的なエラーがあります。
一言で言えば私の主なものは次のとおりです。
main.cpp
#include "sendArrayObj.h"
sendArrayObj* sendqueue;
void foo(){
int i = sendqueue->count()
}
int main(){
int i =10;
sendqueue = new sendArrayObj(i);
foo();
}
sendArrayObj.h
using namespace std;
#include <string.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
class sendArrayObj{
private:
int size,toEnqueue,toDequeue,lastDequeuedInd;
unsigned long long totalEnqueued,totalDequeued;
public:
char** arr;
int* lengths;
sendArrayObj(int size);
void enqueue(string str);
char* dequeue();
int count();
int getDequeuedSize();
};
sendArrayObj.cpp
#include "sendArrayObj.h"
pthread_mutex_t mutex_requestsqueue = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex_count = PTHREAD_MUTEX_INITIALIZER;
sendArrayObj::sendArrayObj( int size){
this->size = size;
toEnqueue = 0;
toDequeue = 0;
totalEnqueued = 0;
totalDequeued = 0;
lastDequeuedInd = -1;
arr = (char**)malloc(size*sizeof(char*));//alloc number of pointers
lengths = (int*)malloc(size*sizeof(int));//alloc number of lengths
}
void sendArrayObj::enqueue(std::string str){
int strSize = str.size();
pthread_mutex_lock( &mutex_requestsqueue );
if (arr[toEnqueue]!= NULL){
free(arr[toEnqueue]);
toDequeue = (toDequeue+1)%size;
totalDequeued++;
}
arr[toEnqueue] = (char*)malloc(strSize);
memcpy(arr[toEnqueue],(char*)str.c_str(),strSize);
lengths[toEnqueue] = strSize;
toEnqueue = (toEnqueue+1)%size;
totalEnqueued++;
pthread_mutex_unlock( &mutex_requestsqueue );
}
char* sendArrayObj::dequeue(){
pthread_mutex_lock( &mutex_requestsqueue );
//allocate memory to the ans
//char* ans = new char[lengths[toDequeue]];
char* ans = arr[toDequeue];
lastDequeuedInd = lengths[toDequeue];
//memcpy(ans,arr[toDequeue],lengths[toDequeue]);
//if (arr[toDequeue]!=NULL){
//delete[] arr[toDequeue];
arr[toDequeue] = NULL;
//}
toDequeue = (toDequeue+1)%size;
totalDequeued++;
//printf("totalDequeued is %d\n",totalDequeued);
pthread_mutex_unlock( &mutex_requestsqueue );
return ans;
}
int sendArrayObj::count(){
pthread_mutex_lock( &mutex_count );
int ans = totalEnqueued-totalDequeued;
pthread_mutex_unlock( &mutex_count );
//printf("count is %d\n",ans);
return ans;
}
int sendArrayObj::getDequeuedSize(){
return lastDequeuedInd;
}
私のコンパイルバッチは
g++ -g -pthread utils/hregex.cpp ExcludeFields.cpp utils/sha1.cpp utils/utils.cpp utils/base64.cpp utils/xmlhelper.cpp utils/messagehelper.cpp utils/safe_queue.cpp utils/parser.cpp utils/default_config.cpp ExcludesParameters.cpp main_process_helper.cpp main.cpp -Iutils -Ibusiness_objects -o telepath_sniff
ファイルは「utils」フォルダーにあります
なぜ私がそれを手に入れているのか分かりますか??
ありがとう