-1

Good morning, I'm implementing this class in C++ but it gives some problem with OCTET_STRING type. In fact, removing those variables it works but obviously I need them too.

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 
             << ")";
}

The error is => error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream’ and ‘const OCTET_STRING’)

P.S. I was also wondering if it is possible to cast a double variable to a OCTET_STRING.

Thank you everybody

Here the 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_ */
FMA
  • 33
  • 1
  • 7

2 Answers2

3

The error message from the compiler is quite clear and unambiguous: there is no

std::ostream& operator<<(std::ostream&, OCTET_STRING const&);

that it can use. If OCTET_STRING was a sensibly defined C++ type, then said operator would have been implemented. The fact that it's missing either means that OCTET_STRINGs should never be used in I/O, that the class has been provided by somebody not very much versed in the art of programming, or that it's a piece of C code that you're abusing.

To remedy, either abandon the use of OCTET_STRING (best) or provide a definition for said operator (ideally inline) yourself.


Note that OCTET_STRING is not a standard C++ type. It appears to be some C struct and a Windows thing. Using it obviously causes problems, but also will render your code non-portable. I can only highly recommend to avoid using OCTET_STRING. W/o much knowledge of what a OCTET_STRING does, I cannot say what to replace it with, but perhaps you know what you're using it for? I.e. what is the real type of Elevation in your code? It seems that double does the job for most if not all of them.

Community
  • 1
  • 1
Walter
  • 44,150
  • 20
  • 113
  • 196
  • The reason for an `OCTET_STRING`, however "sensibly defined", not having a full workable interface could also be if it is a POD trivially adapted from C. – The Vee Dec 02 '16 at 11:24
  • So how should I substitute the OCTET_STRING type? If I have to abandon it I need to define those variables with another typer. – FMA Dec 02 '16 at 11:27
  • @TheVee I'm actually refering to some C codes as a guide line, but I thought OCTET_STRING was an available C++ type as well. So it is not possible to use it? – FMA Dec 02 '16 at 11:29
  • @FMA I don't know if it is a C++ class, one thing that's certain is that it is not standard. (And not straightforward to google.) You should probably include a link (and a tag, preferably) to the framework you're including that from in your question. Anyway it wouldn't mean you can't use it, just that you need to provide the interface yourself, as the answer above says, if you need to use one. – The Vee Dec 02 '16 at 11:34
0

Just write one:

std::ostream& operator<<(std::ostream& os, const OCTET_STRING& whatever)
{
    // print to os
    return os;
}
YSC
  • 38,212
  • 9
  • 96
  • 149
  • do you mean writing twice the function, once for the long values and once for the OCTET_STRING ? because I need both of them – FMA Dec 02 '16 at 11:13
  • Well long should exist by default, but clearly OCTET_STRING does not, so write a method that reflects how you would like to see it! – Zafi Dec 02 '16 at 11:21
  • 3
    You should almost certainly be using `const OCTET_STRING&`. – The Vee Dec 02 '16 at 11:26