Java – namespace issues

I have the following questions I tried to wrap the code from C to Java

COMMON. H

namespace rinad {
namespace mad_manager {

template<class T>
class Encoder{
public:
    virtual ~Encoder(){}
    virtual void encode(const T &obj,ser_obj_t& serobj) = 0;
    virtual void decode(const ser_obj_t &serobj,T& des_obj) = 0;
};
typedef struct ipcp_config{
....
}ipcp_config_t;
}}

encoders. h

namespace rinad {
namespace mad_manager {
class IPCPConfigEncoder: public Encoder<ipcp_config_t> {
public:
    void encode (const ipcp_config_t &obj,ser_obj_t& ser_obj);
    void decode(const ser_obj_t &ser_obj,ipcp_config_t& obj);
    std::string get_type() const{ return "ipcp-config"; };
};
}}

librinad. i

%{
#include "common.h"
#include "encoders.h"
%}
%include "common.h"

%template(TempIPCPConfigEncoder) rinad::mad_manager::Encoder<rinad::mad_manager::ipcp_config_t>;

%include "encoders.h"

However, generated The CC file (swig < Options > - O librarinad_java. CC) does not consider some namespaces that cause errors

librinad_ java. CC: 836:32: error: 'IPCP' is not declared in this scope_ config_ t’ rinad :: mad_ Manager: encoder and lt; ipcp_ config_ t> * arg1 =(rinad :: mad_manager :: Encoder< ipcp_config_t> *)0;

I tried to specify each namespace (even if it wasn't necessary), but it didn't work If I were in librinad_ java. Add namespace rinad:: mad manually in CC_ manager :: ipcp_ config_ T it works, so the problem is that swig will not export this namespace I can't figure out what the problem is here

Side questions I have to encode The code shown in H is the same as that of encoders The code shown in H is separated so that it can be used before instantiation (encoders. H) I, but IPCP is defined in_ config_ After t (common. H)) Is this the only way?

Solution

OK, that's an answer Don't do it

typedef struct ipcp_config{
....
}ipcp_config_t;

but

typedef struct{
....
}ipcp_config_t;

This works for me because I don't need to forward the statement If I need a declaration, I still don't know what to do (for example, in a recursive structure)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>