早上好, 我正在用C ++实现这个类,但它给OCTET_STRING类型带来了一些问题。事实上,删除那些变量,但显然我也需要它们。
class MIXIM_API BSMblob : public cObject
{
public:
long MsgCount;
OCTET_STRING TemporaryID;
long DSecond;
long Latitude;
long Longitude;
OCTET_STRING Elevation;
OCTET_STRING PositionalAccuracy;
OCTET_STRING TransmissionAndSpeed;
long Heading;
OCTET_STRING SteeringWheelAngle;
OCTET_STRING AccelerationSet4Way;
OCTET_STRING BrakeSystemStatus;
/*other line of codes */
/** @brief Returns a string with the value of the BSMblobinate. */
std::string info() const;
};
inline std::ostream& operator<<(std::ostream& os, const BSMblob& BSMblob)
{
return os << "(" << BSMblob.MsgCount << "," << BSMblob.TemporaryID
<< "," << BSMblob.DSecond << "," << BSMblob.Latitude
<< "," << BSMblob.Longitude << "," << BSMblob.Elevation
<< "," << BSMblob.PositionalAccuracy << "," << BSMblob.TransmissionAndSpeed
<< "," << BSMblob.Heading << "," << BSMblob.SteeringWheelAngle
<< "," << BSMblob.AccelerationSet4Way << "," << BSMblob.BrakeSystemStatus
<< ")";
}
错误是=&gt;错误:'operator&lt;&lt;'不匹配(操作数类型为'std :: basic_ostream'和'const OCTET_STRING')
P.S。我也想知道是否可以将双变量转换为OCTET_STRING。
谢谢大家
这里是OCTET_STRING.h:
#ifndef _OCTET_STRING_H_
#define _OCTET_STRING_H_
#include <asn_application.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OCTET_STRING {
uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */
int size; /* Size of the buffer */
asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
} OCTET_STRING_t;
extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
asn_struct_free_f OCTET_STRING_free;
asn_struct_print_f OCTET_STRING_print;
asn_struct_print_f OCTET_STRING_print_utf8;
ber_type_decoder_f OCTET_STRING_decode_ber;
der_type_encoder_f OCTET_STRING_encode_der;
xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */
xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */
xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */
xer_type_encoder_f OCTET_STRING_encode_xer;
xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
per_type_decoder_f OCTET_STRING_decode_uper;
per_type_encoder_f OCTET_STRING_encode_uper;
/******************************
* Handy conversion routines. *
******************************/
/*
* This function clears the previous value of the OCTET STRING (if any)
* and then allocates a new memory with the specified content (str/size).
* If size = -1, the size of the original string will be determined
* using strlen(str).
* If str equals to NULL, the function will silently clear the
* current contents of the OCTET STRING.
* Returns 0 if it was possible to perform operation, -1 otherwise.
*/
int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
/* Handy conversion from the C string into the OCTET STRING. */
#define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
/*
* Allocate and fill the new OCTET STRING and return a pointer to the newly
* allocated object. NULL is permitted in str: the function will just allocate
* empty OCTET STRING.
*/
OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td,
const char *str, int size);
/****************************
* Internally useful stuff. *
****************************/
typedef struct asn_OCTET_STRING_specifics_s {
/*
* Target structure description.
*/
int struct_size; /* Size of the structure */
int ctx_offset; /* Offset of the asn_struct_ctx_t member */
enum asn_OS_Subvariant {
ASN_OSUBV_ANY, /* The open type (ANY) */
ASN_OSUBV_BIT, /* BIT STRING */
ASN_OSUBV_STR, /* String types, not {BMP,Universal}String */
ASN_OSUBV_U16, /* 16-bit character (BMPString) */
ASN_OSUBV_U32 /* 32-bit character (UniversalString) */
} subvariant;
} asn_OCTET_STRING_specifics_t;
#ifdef __cplusplus
}
#endif
#endif /* _OCTET_STRING_H_ */
答案 0 :(得分:3)
来自编译器的错误消息非常明确且明确:没有
std::ostream& operator<<(std::ostream&, OCTET_STRING const&);
它可以使用。如果OCTET_STRING
是一个明智的C ++类型,那么所述运算符就已经实现了。它缺失的事实意味着永远不应该在I / O中使用OCTET_STRING
,该类是由不太熟悉编程艺术的人提供的,或者它是一段C代码你在滥用。
要解决问题,要么放弃使用OCTET_STRING
(最好),要么自己为所述运营商提供定义(理想情况为inline
)。
请注意,OCTET_STRING
不是标准C ++类型。它appears是一些C结构和Windows的东西。使用它显然会导致问题,但也会使代码变得不可移植。我强烈建议避免使用 OCTET_STRING
。我不知道OCTET_STRING
做了什么,我不知道要用什么代替它,但也许你知道你用它做什么?即代码中Elevation
的真实类型是什么?似乎double
为大多数人做了工作,如果不是全部的话。
答案 1 :(得分:0)
只写一个:
std::ostream& operator<<(std::ostream& os, const OCTET_STRING& whatever)
{
// print to os
return os;
}