Share via

Return web::http::status_codes

Flaviu_ 1,091 Reputation points
2021-02-28T16:35:30.87+00:00

How can I return from a method a web::http::status_codes value:

web::http::status_codes CMyClass::GetCode()
{
    return web::http::status_codes::OK;
}

correctly ? Because in this way I got:

error C2440: 'return': cannot convert from 'const web::http::status_code' to 'web::http::status_codes'
note: No constructor could take the source type, or constructor overload resolution was ambiguous

I want to avoid return blind (unknown) int values, or, return static variables.

web::http::status_codes is defined:

typedef unsigned short status_code;

/// <summary>
/// Predefined values for all of the standard HTTP 1.1 response status codes.
/// </summary>
class status_codes
{
public:
#define _PHRASES
#define DAT(a, b, c) const static status_code a = b;
#include "cpprest/details/http_constants.dat"
#undef _PHRASES
#undef DAT
};

from cpprestsdk\include\cpprest\http_msg.h from REST_SDK ?

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments

Answer accepted by question author

Igor Tandetnik 1,116 Reputation points
2021-02-28T17:29:49.64+00:00

Your method should be declared to return web::http::status_code, not status_codes (no s at the end). status_codes is basically just a namespace holding a bunch of constants.

Was this answer helpful?

2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.