Jump to content

C++ Arrays


Guest Kroket

Recommended Posts

  case 4:
      player->ADD_GOSSIP_ITEM( 0, player->GetLatestNews()[0], GOSSIP_SENDER_SERVER_MENU, 3);
      player->ADD_GOSSIP_ITEM( 0, player->GetLatestNews()[1], GOSSIP_SENDER_SERVER_MENU, 3);
      player->ADD_GOSSIP_ITEM( 0, player->GetLatestNews()[2], GOSSIP_SENDER_SERVER_MENU, 3);
      break;

const char* GetLatestNews() {
  QueryResult* result = SiteDatabase.PQuery("SELECT user, title, message FROM news ORDER BY date DESC LIMIT 1");
  Field *fields = result->Fetch();
  const char *res[3] =
   {
   fields[0].GetString(), fields[1].GetString(), fields[2].GetString()
   };

  return res[3];
}

WHAT IS THE PROBLEM?

C++ CANT EVEN READ ARRAYS LOL

error LNK2019: unresolved external symbol "public: char const * __thiscall Player::GetLatestNews(void)" (?GetLatestNews@Player@@QAEPBDXZ) referenced in function "void __cdecl SendServerMenu(class Player *,class Creature *,unsigned int)" (?SendServerMenu@@YAXPAVPlayer@@PAVCreature@@I@Z)
1>..\\..\\..\\..\\bin\\win32_release/MaNGOSScript.dll : fatal error LNK1120: 1 unresolved externals

Link to comment
Share on other sites

  case 4:
      player->ADD_GOSSIP_ITEM( 0, player->GetLatestNews()[0], GOSSIP_SENDER_SERVER_MENU, 3);
      player->ADD_GOSSIP_ITEM( 0, player->GetLatestNews()[1], GOSSIP_SENDER_SERVER_MENU, 3);
      player->ADD_GOSSIP_ITEM( 0, player->GetLatestNews()[2], GOSSIP_SENDER_SERVER_MENU, 3);
      break;

what do you want to do here?

you will access element 0 1 and 2 from an array? but you'll return just one const char* (res[3]) in your function?

you execute the function 3 times (don't know if it even works!) , it would better to save return value localy and access the returned array )

const char* GetLatestNews() {
  QueryResult* result = SiteDatabase.PQuery("SELECT user, title, message FROM news ORDER BY date DESC LIMIT 1");
  Field *fields = result->Fetch();
  const char *res[3] =
   {
   fields[0].GetString(), fields[1].GetString(), fields[2].GetString()
   };

  return res[3];
}

WHAT IS THE PROBLEM?

C++ CANT EVEN READ ARRAYS LOL

error LNK2019: unresolved external symbol "public: char const * __thiscall Player::GetLatestNews(void)" (?GetLatestNews@Player@@QAEPBDXZ) referenced in function "void __cdecl SendServerMenu(class Player *,class Creature *,unsigned int)" (?SendServerMenu@@YAXPAVPlayer@@PAVCreature@@I@Z)
1>..\\..\\..\\..\\bin\\win32_release/MaNGOSScript.dll : fatal error LNK1120: 1 unresolved externals

Link to comment
Share on other sites

const char *res[3] =
   {
   fields[0].GetString(), fields[1].GetString(), fields[2].GetString()
   };

  return res[3];

you can't do that, seems you trying to do vectorial assignations like php/perl, that syntax isn't supported, besides you usingthe wrong types

this looks better for me:

bool GetLatestNews(std::string& user, std::string& title, std::string& msg)
{
   //                                                0     1      2
   QueryResult *result = SiteDatabase.PQuery("SELECT user, title, message FROM news ORDER BY date DESC LIMIT 1");
   if (!result)
       return false;

   Field *fields = result->Fetch();

   user = fields[0].GetCppString();
   title = fields[1].GetCppString();
   msg = fields[2].GetCppString();

   return true;
}

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use