调用对象'char*'类型不是函数或函数指针

Itz*_*984 5 c c++ time xcode

我有这个函数,它应该为给定的char*设置一定的时间格式:

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

strTime和curTime声明如下:

tm* curTime; 
time_t strTime;
Run Code Online (Sandbox Code Playgroud)

但出于某种原因,我得到:

called object type 'char*' is not a function or function pointer
Run Code Online (Sandbox Code Playgroud)

在标记的地方.

任何想法为什么?

我顺便使用xCode.

Dan*_*umb 12

您的函数参数time是指向char的指针.

但是,在您的函数体中,如果它是您可以调用的函数,则会尝试对其进行处理.这就是错误所说的......

类型的对象char *不是函数或函数指针[因此,我无法调用它!]

基本上,您time通过使用同名的局部变量隐藏了该函数.我建议更改函数参数的名称.


Dan*_*her 5

功能参数

static void timeStamp(char* time)
{
  time(&strTime);<---ERROR
  // ...
}
Run Code Online (Sandbox Code Playgroud)

遮蔽time()功能.重命名参数.

  • 我_have_读它们,我只是不认为这是以这种方式解决问题的好方法.我在上面解释过. (2认同)