简体   繁体   中英

C++ compilation issue

I am seeing some C++ errors I don't understand (I am java centric coder):

WarningNotification_if.cpp: In function 'void fireStatusBarMessage(char*, int)':
WarningNotification_if.cpp:62:14: error: expected type-specifier
WarningNotification_if.cpp:62:14: error: cannot convert 'int*' to 'WarningEventData*' in initialization
WarningNotification_if.cpp:62:14: error: expected ',' or ';'

Here is the actual code:

void fireStatusBarMessage(char *message = 0, int aTime = 0 )
{
   LmLocker locker( (char *)__FILE__, __LINE__, &WarningEventUpdateMutex );
   HMI_DEBUG(EVENT_DEBUG, (stderr, "Fire Status Bar Message\n") );
   if ( message != 0 )
   {
      QString warningMessage = QString( message );
      WarningEventData *theEventData = 
         new WarningEventData::WarningEventData();
      theEventData->initialize();
      theEventData->setMessageType( SESSION_STATUSBAR_TYPE );
      theEventData->setCommand( APPEND_WARNING );
      theEventData->setMessage( warningMessage );
      theEventData->setModifier( aTime );
      theEventData->setCategory( SESSION_STATUSBAR_TYPE );
      WarningNotification::fireChange( SESSION_STATUSBAR_TYPE, theEventData );
   } /* endif - message contents */
}

Do I need to be importing something else or using a certain -D flag?

WarningEventData *theEventData = new WarningEventData::WarningEventData();

This is quite odd. A new expression is supposed to name a type, not a constructor. Is WarningEventData inside a like-named namespace? And if so, why isn't it WarningEventData::WarningEventData* theEventData ?

WarningEventData *theEventData = new WarningEventData::WarningEventData();
                                   // ^^^^^^^^^^^^^ Is WarningEventData is a namespace ?

If so, then you have to instantiate like -

WarningEventData::WarningEventData *theEventData = 
     new WarningEventData::WarningEventData();

If there is no namespace involved at all -

WarningEventData *theEventData = new WarningEventData();

Been a while since I did c++, but I believe the constructor does not expect an explicit call. Try replacing

WarningEventData *theEventData = new WarningEventData::WarningEventData();

with

WarningEventData *theEventData = new WarningEventData();

It looks like you might need to include the file with the declaration of WarningEventData, as with

#include "WarningEventData.h"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM