尝试升级/编译旧的 C++ 源代码(来自供应商)-“std::runtime_error”问题

问题描述 投票:0回答:1

我正在尝试从我们使用的产品中编译一些示例代码。我认为供应商没有维护代码。我使用的是 VS Pro 2022 版本 17.7.5 这是代码片段及其生成的错误。我已经 15 年没有使用过 C++ 或 Visual Studio。我记得一切都更加复杂和晦涩。 我正在尝试修复第 17 行的“runtime_error”问题。我无法理解相关文档。我尝试过在第 17 行的内容周围加上括号来对其进行霰弹枪攻击,但没有成功。

/* ReadDynaRecordListWithWhere.cpp : Defines the entry point for the console application.
    The purpose of this example is to show how to define a dynamic query and read only
    requested column data from the TeamTrack database. This example shows how to request
    information about the users who are members of the "Everyone" group in TeamTrack.
*/

#include "stdafx.h"
#include <stdio.h>
#include <new.h>
#include "TSServer.h"
#include "TSDynaRecordList.h"

// Create these before we start because when a memory allocation
// fails it will bee too late (no memory to create new stuff).
static const char * memoryMessage = "Memory allocation failed.";
#ifdef WIN32
static const std::runtime_error bad_alloc( memoryMessage );  // *** Line #17

// Define a function to be called if new fails to allocate memory.
int TSNewHandler( size_t size )
{
  printf( "Throwing: %s\n", memoryMessage );
  throw bad_alloc;                                           // *** Line #23
  return NULL;
}
#endif

错误列表:

Severity  Code   Description                                                                    Line
Error     C2039  'runtime_error': is not a member of 'std'                                      17    
Message          see declaration of 'std'                                                       25    
Error     C4430  missing type specifier - int assumed. Note: C++ does not support default-int   17    
Error     C2146  syntax error: missing ';' before identifier 'bad_alloc'                        17    
Error     C4430  missing type specifier - int assumed. Note: C++ does not support default-int   17    
Error     C2040  'memoryMessage': 'int' differs in levels of indirection from 'const char *'    17    
Error     C2065  'bad_alloc': undeclared identifier                                             23    
c++ std visual-studio-2022
1个回答
0
投票

问题解决了。查看之前的编辑。

© www.soinside.com 2019 - 2024. All rights reserved.