Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

called object 'char* 'type is not a function or function pointer

Tags:

c++

c

time

xcode

I have this function which is supposed to set a certain time format to the given char*:

static void timeStamp(char* time)
{
  time(&strTime);<---ERROR
  curTime = std::localtime(&strTime);
  strftime(time, 8, "%H:%M::", curTime);    
}

strTime and curTime were declared like this:

tm* curTime; 
time_t strTime;

but for some reason i get:

called object type 'char*' is not a function or function pointer

on the marked place.

any idea why?

im using xCode by the way.

like image 482
Itzik984 Avatar asked Jun 20 '12 12:06

Itzik984


3 Answers

Your function parameter time is a pointer to a char.

However, in your function body, you're trying to treat it if it were a function that you can call. That's what the error is saying...

the object of type char * is not a function or a function pointer [therefore, I can't call it!]

Essentially, you've hidden the time function by having a local variable of the same name. I'd recommend changing your function parameter's name.

like image 96
Dancrumb Avatar answered Oct 31 '22 14:10

Dancrumb


The function parameter

static void timeStamp(char* time)
{
  time(&strTime);<---ERROR
  // ...
}

shadows the time() function. Rename the parameter.

like image 21
Daniel Fischer Avatar answered Oct 31 '22 14:10

Daniel Fischer


static void timeStamp(char* time)  

here, this char* time parameter is hidding the function time().you will need to rename it.

like image 2
Eight Avatar answered Oct 31 '22 13:10

Eight