C++ code doesnt compile because multiple symbol error - c++

I tried to compile the below code:
Here is the server.h code (https://codeshare.io/an3XW4)
///////////////HEADER FILES///////////////
#include <pthread.h>
#include "Server.h"
///////////////FUNCTIONS///////////////
/*Thread Main Function
Variable Definition:
-- thread_arguments: arguments which thread should be used
Return Value: NULL
*/
void *threadMain(void *thread_arguments){
int client_socket; //socket descriptor for client
//Guarantees that thread resources are deallocated upon return
pthread_detach(pthread_self());
//Pass the arguments
client_socket = ((THREAD_ARGUMENTS*)thread_arguments)->client_socket;
//Deallocate memory for argument
free(thread_arguments);
//Handle the client request
handleClientRequest(client_socket);
return (NULL);
}
THIS IS TIMEUTILITY.C, i dont understand much about C, im a programmer in java and more higher level languages of that sort.
///////////////HEADER FILES///////////////
#include <sys/stat.h>
#include <time.h>
#include "Server.h"
///////////////FUNCTIONS///////////////
/*Set Timer Function
Variable Definition:
-- timer: itimerval structure
-- type: timer type
-- interval_sec: it_interval seconds
-- interval_usec: it_interval microseconds
-- value_sec: it_value seconds
-- value_usec: it_value microseconds
Return value: NULL
*/
void setTimer( struct itimerval timer,
int type,
u_int32 interval_sec,
u_int32 interval_usec,
u_int32 value_sec,
u_int32 value_usec){
//Set the time out value
timer.it_interval.tv_sec = interval_sec;
timer.it_interval.tv_usec = interval_usec;
//Set the first time out value
timer.it_value.tv_sec = value_sec;
timer.it_value.tv_usec = value_usec;
//Set the timer
if (setitimer(type, &timer, NULL) != 0){
dieWithSystemMessage("setitimer() failed");
}
return;
}
/*Get GMT Time Function (including System time and File time)
Variable Definition:
-- url: the request url except domain name and port number
-- signal_value: signal that decide which kind of time needed
Return value: tm struct in GMT Format
*/
struct tm *getTimeInGMTFormat(char *url, int signal_value){
struct stat file_information; //file information sstructure
time_t t; //time structure
//signal_value equals to 0, get the system current time
if (!signal_value){
time(&t);
}
//signal_value not equals to 0, get the file time(Create time, Modify time, Access time...)
else if (stat(url, &file_information) != -1){
switch(signal_value){
//signal_value is 1, get the file create time
case 1: t = file_information.st_atime; break;
//signal_value is 2, get the file modify time
case 2: t = file_information.st_mtime; break;
//signal_value is others
default: break;
}
}
//Cannot find the file information
else{
dieWithUserMessage("stat() failed(cannot find the file information), file name", url);
}
return gmtime(&t);
}
/*Convert Time Format to a string
Variable Definition:
-- gmt_time: tm struct in GMT format
-- signal_value: signal that decide which time format to convert
Return value: time string in GMT format
*/
char *convertTimeFormat(struct tm *gmt_time, int signal_value){
char *gmt_time_string = (char*)malloc(sizeof(char) * (TIME_SIZE + 1)); //time in GMT format string
//According to the signal_value, convert time to different format
switch(signal_value){
case 1:
strftime(gmt_time_string, TIME_SIZE, "%a, %d %b %Y %H:%M:%S GMT", gmt_time);
break;
case 2:
strftime(gmt_time_string, TIME_SIZE, "%A, %d-%b-%y %H:%M:%S GMT", gmt_time);
break;
case 3:
gmt_time_string = asctime(gmt_time);
gmt_time_string[strlen(gmt_time_string) - 1] = '\0';
break;
default:
break;
}
return gmt_time_string;
}
/*Compare the If-Modified-Since field and Last-Modified field Function
Variable Definition:
-- url: the request url except domain name and port number
-- modified_time_string: If-Modified-Since field value
Return Value: if If-Modified-Since field equals to Last-Modified field, return 1; else return 0
*/
bool compareModifiedTime(char *url, char *modified_time_string){
struct tm *file_modified_time = getTimeInGMTFormat(url, 2); //tm struct with the file last modified time
int i; //counter
//Test the modified time is equal(three format: RFC 1123, RFC 1036, and ANSI C's format)
for (i = 1; i < NUMBER_SIZE; i++){
if (strcmp(modified_time_string, convertTimeFormat(file_modified_time, i)) == 0){
return true;
}
}
return false;
}
But when I try to compile it, using g++ (C++ compiler) (the code was natively written in C), i get a weird error, anyone understand why? This is the full code of the Thread.C
/home/justin/Documents/dcn_streaming_video/server/Thread.c:23: multiple definition of `client_rtcp_port'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:36: first defined here
Thread.o: In function `threadMain(void*)':
/home/justin/Documents/dcn_streaming_video/server/Thread.c:23: multiple definition of `client_rtp_port'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:36: first defined here
Thread.o: In function `threadMain(void*)':
/home/justin/Documents/dcn_streaming_video/server/Thread.c:27: multiple definition of `range_end'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:37: first defined here
Thread.o: In function `threadMain(void*)':
/home/justin/Documents/dcn_streaming_video/server/Thread.c:27: multiple definition of `range_start'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:37: first defined here
Thread.o: In function `threadMain(void*)':
/home/justin/Documents/dcn_streaming_video/server/Thread.c:27: multiple definition of `status'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:39: first defined here
Thread.o: In function `threadMain(void*)':
/home/justin/Documents/dcn_streaming_video/server/Thread.c:31: multiple definition of `session_id'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:39: first defined here
Thread.o: In function `threadMain(void*)':
/home/justin/Documents/dcn_streaming_video/server/Thread.c:33: multiple definition of `rtp_address'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:40: first defined here
Thread.o:(.bss+0x50): multiple definition of `protocol_method'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:55: first defined here
Thread.o:(.bss+0x60): multiple definition of `protocol_type'
TimeUtility.o:/home/justin/Documents/dcn_streaming_video/server/TimeUtility.c:60: first defined here

As others have indicated, I do not see the whole source code, specifically, the Server.h which probably does not use multiple inclusion guards (i.e top level ifdef or pragma once).

Related

setKind() not taken into account

I'm trying to Identify a message by using the getKind() function, I've previously defined my own DATA_KIND
for sending:
DataM *data = new DataM();
data ->setKind(DATA_KIND);
data ->setSrc(this->getParentModule()->getIndex());
socket.sendTo(data, destAddr, destPort);
for receiving which it bypasses but is received as as a UDP_I_DATA
bypasses this:
else if (msg->getKind() == DATA_KIND) {
// process incoming packet;
}
and uses this:
else if (msg->getKind() == UDP_I_DATA) {
// process incoming packet;
}
Please help!
I have tried adding the DATA_KIND value to the .h files and to the .cc files, I thought it was about the scope, it didn't work
You cannot use setKind()/getKind() to carry out own information across the whole network in INET. Kind is a metadata that is used mainly between modules inside a device - to inform about the status of a packet. Therefore UDP layer always sets the value of kind for received packets (e.g.UDP_I_DATA, UDP_I_ERROR).
I suggest introducing own packet with the field that will determine the type, e.g. 1 - MY_DATA, 2 - MY_CONTROL, etc.
An example:
packet DataM {
int myType; // own type
// other data
int otherData;
}
Then in your code you may use:
// somewhere in *.h
#define MY_DATA 1
#define MY_CONTROL 2
// in *.cc - sending
DataM *data = new DataM();
data->setMyType(MY_DATA);
// in *.cc - receiving
DataM *data2 = dynamic_cast<DataM*>(msg);
if (data2 != nullptr) {
if (data2->getMyType == MY_DATA) {
// MY_DATA - do something
}
}
References:
OMNeT++ Simulation Manula - 6 Message Definitions
TicToc Tutorial - 4.4 Defining our message class

undefined reference to `FIFORequestChannel::FIFORequestChannel

I am trying to copy data values from one .csv file to another, but when I am compiling I keep getting an undefined reference error. I am confused because I made sure to include the header file. Can anyone provide any input?
client.cpp (main):
#include "common.h"
#include "FIFOreqchannel.h" // this is where I included the header file
#include <iostream>
#include <string>
#include <stdio.h>
#include <sys/wait.h>
using namespace std;
int main(int argc, char *argv[]){
cout<<"test"<<endl;
int n = 100; // default number of requests per "patient"
int p = 15; // number of patients
srand(time_t(NULL));
struct timeval tv; // this is the starting struct
struct timeval ts;// this is the ending struct
gettimeofday(&tv, NULL); // starts the clock
FIFORequestChannel chan ("control", FIFORequestChannel::CLIENT_SIDE); // this is the creation of the server
//datamsg first = datamsg(1,59.996, 2); // This is the creation of the first datamsg. It gets the information for the first person, up to 59.996 seconds, and gets info from the second ecg.
//The next step is to create the file
string file = "x1.csv";
//gettimeofdayI(&start, null);
ofstream inputfile;
inputfile.open(file); // opens the data for the first person
double seconds = 0.0;
while (seconds<59.996){
datamsg ecg1 = datamsg(1,seconds,1); // gets the data from the first ECG
datamsg ecg2 = datamsg(1,seconds,2); // gets the data from the second ECG
//cout<<test<<endl;
char*size= new char [sizeof(ecg1)];
*(datamsg*)size=ecg1;
chan.cwrite(size,sizeof(ecg1));
char * read=chan.cread();
double ecgfirst=*(double*)read;
inputfile<<ecgfirst<<","<<"\n";
char*size2= new char [sizeof(ecg2)];
*(datamsg*)size2=ecg2;
chan.cwrite(size2,sizeof(ecg2));
char * read2=chan.cread();
double ecgsecond=*(double*)read2;
inputfile<<ecgsecond<<","<<"\n";
seconds = seconds +.004; // this is the incrementation of the seconds
}
inputfile.close();
gettimeofday(&ts, NULL);
double totaltime; // this will count the total time of the process
totaltime = ts.tv_sec-tv.tv_sec;
cout<<" The total time to get the info for person is "<<totaltime<<"."<<endl;
// sending a non-sense message, you need to change this
char x = 55;
chan.cwrite (&x, sizeof (x));
char* buf = chan.cread ();
// closing the channel
MESSAGE_TYPE m = QUIT_MSG;
chan.cwrite (&m, sizeof (MESSAGE_TYPE));
}
FIFOreqchannel.h:
#ifndef _FIFOreqchannel_H_
#define _FIFOreqchannel_H_
#include "common.h"
class FIFORequestChannel
{
public:
enum Side {SERVER_SIDE, CLIENT_SIDE};
enum Mode {READ_MODE, WRITE_MODE};
private:
/* The current implementation uses named pipes. */
string my_name;
Side my_side;
int wfd;
int rfd;
string pipe1, pipe2;
int open_pipe(string _pipe_name, int mode);
public:
FIFORequestChannel(const string _name, const Side _side);
/* Creates a "local copy" of the channel specified by the given name.
If the channel does not exist, the associated IPC mechanisms are
created. If the channel exists already, this object is associated with the channel.
The channel has two ends, which are conveniently called "SERVER_SIDE" and "CLIENT_SIDE".
If two processes connect through a channel, one has to connect on the server side
and the other on the client side. Otherwise the results are unpredictable.
NOTE: If the creation of the request channel fails (typically happens when too many
request channels are being created) and error message is displayed, and the program
unceremoniously exits.
NOTE: It is easy to open too many request channels in parallel. Most systems
limit the number of open files per process.
*/
~FIFORequestChannel();
/* Destructor of the local copy of the bus. By default, the Server Side deletes any IPC
mechanisms associated with the channel. */
char* cread(int *len=NULL);
/* Blocking read of data from the channel. Returns a string of characters
read from the channel. Returns NULL if read failed. */
int cwrite(void *msg, int msglen);
/* Write the data to the channel. The function returns the number of characters written
to the channel. */
string name();
};
#endif
FIFOreqchannel.cpp:
#include "common.h"
#include "FIFOreqchannel.h"
using namespace std;
/*--------------------------------------------------------------------------
*/
/* CONSTRUCTOR/DESTRUCTOR FOR CLASS R e q u e s t C h a n n e l */
/*--------------------------------------------------------------------------
*/
FIFORequestChannel::FIFORequestChannel(const string _name, const Side _side)
: my_name( _name), my_side(_side){
pipe1 = "fifo_" + my_name + "1";
pipe2 = "fifo_" + my_name + "2";
if (_side == SERVER_SIDE){
wfd = open_pipe(pipe1, O_WRONLY);
rfd = open_pipe(pipe2, O_RDONLY);
}
else{
rfd = open_pipe(pipe1, O_RDONLY);
wfd = open_pipe(pipe2, O_WRONLY);
}
}
FIFORequestChannel::~FIFORequestChannel(){
close(wfd);
close(rfd);
remove(pipe1.c_str());
remove(pipe2.c_str());
}
int FIFORequestChannel::open_pipe(string _pipe_name, int mode){
mkfifo (_pipe_name.c_str (), 0600);
int fd = open(_pipe_name.c_str(), mode);
if (fd < 0){
EXITONERROR(_pipe_name);
}
return fd;
}
char* FIFORequestChannel::cread(int *len){
char * buf = new char [MAX_MESSAGE];
int length = read(rfd, buf, MAX_MESSAGE);
if (length < 0){
EXITONERROR ("Connection Error");
}
if (len) // the caller wants to know the length
*len = length;
return buf;
}
int FIFORequestChannel::cwrite(void* msg, int len){
if (len > MAX_MESSAGE){
cerr << "message length exceeds buffer size" << endl;
exit (-1);
}
if (write(wfd, msg, len) < 0){
EXITONERROR("cwrite");
}
return len;
}
The errors I am getting are undefined reference errors. So, I assume that it is a problem with linking, but I am confused because I included the header file.
Here are the errors I am getting:
client.cpp:(.text+0xc8): undefined reference to
`FIFORequestChannel::FIFORequestChannel(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, FIFORequestChannel::Side)'
client.cpp:(.text+0x22e): undefined reference to `FIFORequestChannel::cwrite(void*, int)'
client.cpp:(.text+0x242): undefined reference to `FIFORequestChannel::cread(int*)'
client.cpp:(.text+0x2f3): undefined reference to `FIFORequestChannel::cwrite(void*, int)'
client.cpp:(.text+0x307): undefined reference to `FIFORequestChannel::cread(int*)'
client.cpp:(.text+0x446): undefined reference to `FIFORequestChannel::cwrite(void*, int)'
client.cpp:(.text+0x45a): undefined reference to `FIFORequestChannel::cread(int*)'
client.cpp:(.text+0x489): undefined reference to `FIFORequestChannel::cwrite(void*, int)'
client.cpp:(.text+0x4b6): undefined reference to `FIFORequestChannel::~FIFORequestChannel()'
client.cpp:(.text+0x54d): undefined reference to `FIFORequestChannel::~FIFORequestChannel()'
collect2: error: ld returned 1 exit status
I am using Cloud 9 IDE on Amazon Webservices, and all the files are in the same folder.
I am confused because I made sure to include the header file.
Using #include "FIFOreqchannel.h" is necessary, but not sufficient to link your program. You must also supply FIFOreqchannel.o to the linker.
You are doing something like:
g++ client.cpp
You should do:
g++ client.cpp FIFOreqchannel.cpp ...other_object_files... ...other_libraries...

linux c++ how to call function after specific time interval

Let's say I have some function func() in my program, and I need it to be called after some specific delay. So far I have googled it and ended up with folowing code:
#include <stdio.h>
#include <sys/time.h> /* for setitimer */
#include <unistd.h> /* for pause */
#include <signal.h> /* for signal */
void func()
{
printf("func() called\n");
}
bool startTimer(double seconds)
{
itimerval it_val;
double integer, fractional;
integer = (int)seconds;
fractional = seconds - integer;
it_val.it_value.tv_sec = integer;
it_val.it_value.tv_usec = fractional * 1000000;
it_val.it_interval = it_val.it_value;
if (setitimer(ITIMER_REAL, &it_val, NULL) == -1)
return false;
return true;
}
int main()
{
if (signal(SIGALRM, (void(*)(int))func) == SIG_ERR)
{
perror("Unable to catch SIGALRM");
exit(1);
}
startTimer(1.5);
while(1)
pause();
return 0;
}
And it works, but the problem is that settimer() causes func() to be called repeatedly with interval of 1.5 sec. And what I need, is to call func() just once.
Can someone tell me how to do this? Maybe, I need some additional parameters to settimer() ?
Note: time interval should be precise, because this program will play midi music later.
Unless you need the program to be doing other things, you can simply sleep for the time allotted.
If you need to use the alarm, you can install the alarm to be processed once.
From the man page:
struct timeval it_interval
This is the period between successive timer interrupts. If zero, the alarm will only be sent once.
Instead of your code:
it_val.it_interval = it_val.it_value;
I'd set:
it_val.it_interval.tv_sec = 0;
it_val.it_interval.tv_usec = 0;
In addition to it_val.it_value which you already set. What you've done is use the same values for both structures, and that is why you see a repeated interval.

XBee, external libraries and passing structures as arguments

I have very weird problem with a library I am creating. The library will be used to communicate between Arduino modules using XBee Series 1 modules. Library is very simple wrapper library around Arduino XBee library.
I have one function that reads received packet and sends it back. At the moment it is implemented as a simple "echo" service - the function just displays the data received and sends it back to per-defined address.
At the moment I have three versions of this function, out of which one is not working.
A function taking no arguments: void processPacket()
A function taking structure as a value as an argument: void processPacket(valuesStruct valuesStructData) - THIS VERSION OF THE FUNCTION IS NOT WORKING!
A function taking pointer to the structure as an argument: void processPacket(valuesStruct* valuesStructData)
At this moment I noticed strange behavior in the 2nd version of the function. I do nothing with the passed argument - the content of all three functions is the same. In 2nd case the function reads wrong values from received XBee packet. In the 1st and 3rd case the function performs correctly.
Code:
ExampleLib.h
#ifndef ExampleLib_h
#define ExampleLib_h
#include "Arduino.h"
#include <XBee.h>
#define ADDRESS_BROADCAST 0xffff
#define ADDRESS_PC 0x3333
typedef struct
{
int valA;
int valB;
int valC;
} valuesStruct;
class ExampleLib
{
public:
ExampleLib();
void setSerial(Stream &serial);
boolean tryReceivePacket();
void processPacket();
// THIS FUNCTION IS NOT WORKING!
void processPacket(valuesStruct valuesStructData);
void processPacket(valuesStruct* valuesStructData);
private:
XBee xbee;
Rx16Response rx16;
};
#endif
ExampleLib.cpp
The value read in line byte* packetData = rx16.getData(); is wrong when we trigger processPacket(valuesStruct valuesStructData) function. In other cases the behavior is correct.
#include "Arduino.h"
#include <XBee.h>
#include "ExampleLib.h"
ExampleLib::ExampleLib()
{
xbee = XBee();
rx16 = Rx16Response();
}
void ExampleLib::setSerial(Stream &serial)
{
xbee.setSerial(serial);
}
boolean ExampleLib::tryReceivePacket()
{
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
// got something
if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
// got a rx packet
xbee.getResponse().getRx16Response(rx16);
return true;
}
else {
return false;
}
}
else if (xbee.getResponse().isError()) {
//nss.print("Error reading packet. Error code: ");
//nss.println(xbee.getResponse().getErrorCode());
// or flash error led
return false;
}
return false;
}
void ExampleLib::processPacket()
{
byte* packetData = rx16.getData();
byte dataLength = rx16.getDataLength();
Serial.print("START L:");
Serial.println(dataLength);
for (int i = 0; i < dataLength; i++) {
Serial.print(packetData[i]);
Serial.print(" - ");
}
Serial.println("END");
//16-bit addressing: Enter address of remote XBee, typically the coordinator
Tx16Request tx = Tx16Request(ADDRESS_PC, packetData, sizeof(packetData));
xbee.send(tx);
}
void ExampleLib::processPacket(valuesStruct valuesStructData)
{
processPacket();
}
void ExampleLib::processPacket(valuesStruct* valuesStructData)
{
processPacket();
}
Arduino sketch
#include <XBee.h>
#include <ExampleLib.h>
ExampleLib exampleLibObj = ExampleLib();
void setup()
{
Serial.begin(9600);
exampleLibObj.setSerial(Serial);
}
void loop()
{
boolean isPacketReceived = exampleLibObj.tryReceivePacket();
if (isPacketReceived) {
// leave only one section, the rest should be commented
//Section 1: working
exampleLibObj.processPacket();
//Section 2: not working
// valuesStruct test;
// test.valA = 0;
// test.valB = 0;
// test.valC = 0;
// exampleLibObj.processPacket(test);
//Section 3: working
// valuesStruct* test;
// test->valA = 0;
// test->valB = 0;
// test->valC = 0;
// exampleLibObj.processPacket(test);
}
}
I am really puzzled why in this one case function is performing differently. Looking forward to any suggestions to that issue.
Thanks,
Michal
Are you sure it isn't your section 3 that's causing problems? Because you're declaring a pointer to a structure, but not allocating memory for that structure.
You'd typically write your code like this:
valuesStruct test;
test.valA = 0;
test.valB = 0;
test.valC = 0;
//Section 2: not working
exampleLibObj.processPacket(test);
//Section 3: working
exampleLibObj.processPacket(&test);
But you also wouldn't typically pass a structure to a function -- you'd pass a pointer to that structure. There really isn't a need for your second sample.

c++ Calling class method inside same method

I´m writing the clsLog class:
// This is the main DLL file.
#include "stdafx.h"
#include <time.h>
#include <fstream>
#include <iostream>
#include <string>
#include "clsLog.h"
std::string m_strCurLogUser;
int m_iCurLogAction;
int m_iCurLogLevel;
std::ofstream m_oCurLogFile;
//
// LogInit
// Initilize the log parameters of the system.
// The FileName will be the file name that the system will log the messages (LOG.TXT is the default if no names are given).
// The DatabaseName and TableName specifies the database and table name to be used for log. The default is "LOG_DATABASE" and "LOG_TABLE"
// will be done.
// The Action shall be an OR with all the options. Att: If an option is giver (ex: Database) and an invalid name is given, then an error will occur.
//
// The default log level is zero (0). So every log with a level upper than that will be logged. A change to the level must be done
// using the SetLogLevel method.
//
// return = 0: Success
// 1: Failure
//
int LogInit (std::string FileName, // Initialize the log file/connection.
std::string DatabaseName, // Database name to connect to.
std::string TableName, // Table name to connect to.
std::string UserName, // User name to log into
int Action) // Action to be done.
{
//
// If the file is already open, someone is calling that function before closing the previous one. Error.
//
if (m_oCurLogFile.is_open ())
{
std::string msg;
msg = "LogInit called for " + FileName + " witout closing previous session. Error";
this->clsLog::Log (msg);
}
// Do some stuff
return 0;
}
//
// Log
// Logs the Message according to its Level.
//
// return = 0: Success
// 1: Failure
//
int Log (std::string Message, int Level) // Register a log according to the log state.
{
time_t now;
struct tm ptm;
char buffer [32];
//
// If the sent message level is below the current level, abort.
//
if (Level < m_iCurLogLevel)
return 1;
// Get the current date and time and convert it to the time structure (ptm)
now = time (NULL);
localtime_s (&ptm, &now);
//
// Format the time structure: DD/MM/AAAA HH:MM:SS)
strftime (buffer, 32, "%D/%M/%Y %H:%M:%S", &ptm);
// Check if needs to be logged on stdio
//
if ((m_iCurLogLevel & LOGACTION_STDOUT) == LOGACTION_STDOUT)
{
cout << buffer + " " + Message;
}
return 0;
}
I´m not being able to compile. I´m getting the following error at
this->clsLog::Log (msg);
C2227 error on left of '->Log' must point to a class/struct/union/generic type. Using VS2010, Win32 application.
Help appreciated.
Rds
I don't see any evidence that your functions are inside a class definition; therefore, as the error message says, there's no "this" pointer available. "This" is only available in the instance members of a class.
The this pointer is only valid inside a method that is a (non-static) member of a class or struct. There is no this for a plain function such as LogInit.