user3929846
user3929846

Reputation: 13

C++ Compiler using wrong function declaration

I am having an issue where I am getting conflicting function names from two different libraries I am including. I am attempting to use the gettimeofday function from sys/time.h, but the compiler is trying to use ACE_Task::gettimeofday.

I am not sure why the compiler is implicitly using that 'ACE_Task' namespace, as there are no explicit 'using namespace ACE_Task' or similar. I am fairly inexperienced with C++, so I don't know how to explicitly tell the compiler to use the sys/time.h's definition.

log4cpp_common_macros.h:26:23: error: no matching function for call to ‘Project::Messenger::gettimeofday(timeval*, int)’
    gettimeofday(&tv, 0); 

... (repeat errors/notes about the same line)

In file included from /usr/share/ace/ace/Task_T.h:187:0,<br>
 from /usr/share/ace/ace/Task.h:303,<br>
 from libmessenger/io/TP_SenderTask.h:20,<br>
 from libmessenger/Messenger.h:24,<br>
 from libmessenger/Messenger.cpp:15:<br>

/usr/share/ace/ace/Task_T.inl:70:1: note: ACE_Time_Value_T<TIME_POLICY> ACE_Task<_ACE_SYNCH, TIME_POLICY>::gettimeofday() const [with _ACE_SYNCH = ACE_MT_SYNCH; TIME_POLICY = ACE_System_Time_Policy]
 ACE_Task<ACE_SYNCH_USE, TIME_POLICY>::gettimeofday (void) const

Below is the offending piece of the code (edit: from log4cpp_common_macros.h):

#include "log4cpp_wrapper.h"
#include <sys/time.h>

#define STDERR_FORMAT_TIME(time_str)                                    \
{                                                                       \
   struct tm ptm;                                                       \
   struct timeval tv;                                                   \
   gettimeofday(&tv, 0);                                                \                                                                         
   time_t t = tv.tv_sec;                                                \
   gmtime_r(&t, &ptm);                                                  \
   strftime(time_str, sizeof(time_str), "%Y/%m/%d %H:%M:%S", &ptm);     \
}

Messenger.cpp :

#include "Messenger.h"     // here is include for the stack going to ACE_Task                                                                                                                       
#include "Messenger.inl"

#include "libmessenger/io/TP_IO_Connector.h"
#include "libmessenger/io/TP_IO_Handler.h"

#include "common/Utils.h"
#include "log4cpp_common_macros.h"  // here is the include for the macros

Messenger.h :

#include "common/CIN_Defs.h"
#include "Message.h"
#include "MessagesProcessor.h"

#include <vector>
#include <set>

#include "libmessenger/MessagesProcessor.h"
#include "libmessenger/io/TP_SenderTask.h"

#include "ace/Guard_T.h"
#include "ace/Recursive_Thread_Mutex.h"

From io/TP_SenderTask.h:

#ifndef   TP_SenderTask_h
#define  TP_SenderTask_h

#include "common/CIN_Defs.h"

#include <list>

#include "ace/Task.h"

Upvotes: 1

Views: 412

Answers (1)

Overv
Overv

Reputation: 8529

You can use the definition outside the ACE_Task namespace by prepending the call with :::

::gettimeofday(&tv, 0);

Upvotes: 4

Related Questions