Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CGO,将结构从go传递到c++; 我正在试用CGO,希望用C++来使用CGO。我找到了关于做这件事的帖子。如果我有一个C++结构,名为“代码> Foo< /Cube >,并且一个GO结构名为 Foo,我想把GO Foo传递给C++。我试着这样做: //bind.h #ifdef __cplusplus extern "C" { #endif #include "structs.hpp" void bindCgo(Foo bar); #ifdef __cplusplus } #endif_C++_C_Go_Struct_Cgo - Fatal编程技术网

CGO,将结构从go传递到c++; 我正在试用CGO,希望用C++来使用CGO。我找到了关于做这件事的帖子。如果我有一个C++结构,名为“代码> Foo< /Cube >,并且一个GO结构名为 Foo,我想把GO Foo传递给C++。我试着这样做: //bind.h #ifdef __cplusplus extern "C" { #endif #include "structs.hpp" void bindCgo(Foo bar); #ifdef __cplusplus } #endif

CGO,将结构从go传递到c++; 我正在试用CGO,希望用C++来使用CGO。我找到了关于做这件事的帖子。如果我有一个C++结构,名为“代码> Foo< /Cube >,并且一个GO结构名为 Foo,我想把GO Foo传递给C++。我试着这样做: //bind.h #ifdef __cplusplus extern "C" { #endif #include "structs.hpp" void bindCgo(Foo bar); #ifdef __cplusplus } #endif,c++,c,go,struct,cgo,C++,C,Go,Struct,Cgo,现在当我运行这个程序时,它会给我sΘ\。这正常吗?我该如何修复 我的结构中也有贴图和向量,因此使用char*将不起作用似乎永远不会起作用 STD::String 是C++类,GO不与C++一起播放,C.不理解GO STR < /C>类型,只需传递基元类型 //structs.hpp #ifndef STRUCTS_HPP_ #define STRUCTS_HPP_ typedef struct Foo { #ifdef __cplusplus std::string str;

现在当我运行这个程序时,它会给我
sΘ\
。这正常吗?我该如何修复


我的结构中也有贴图和向量,因此使用char*将不起作用

似乎永远不会起作用<代码> STD::String 是C++类,GO不与C++一起播放,C.不理解GO <代码> STR < /C>类型,只需传递基元类型
//structs.hpp

#ifndef STRUCTS_HPP_
#define STRUCTS_HPP_

typedef struct Foo {

  #ifdef __cplusplus
  std::string str;
  #endif

}
#endif
//bind.cc

#include "structs.hpp"
using namespace std;

void bindCgo(Foo bar) {
  cout << bar.str << endl; //this gives "sΘ\"
}

//main.go

import "unsafe"

// #cgo CFLAGS: -std=c99
// #include "bind.h"
import "C"

type Foo struct {
  str string
}

func main() {
  bar := Foo{""};

  C.bindCgo(((*C.Foo)(unsafe.Pointer(&bar))))
}