小编fra*_*an1的帖子

Linux中的Google protobuf

我正在使用protobuf和Linux.它在哪里是编译器protoc.我已经从主站点下载了包,成功编译并安装了它,但我找不到protoc来构建我自己的格式文件.它在哪里?

UPD 这是我建立protobuf的文件夹:

aclocal.m4        depcomp                       Makefile.in
autogen.sh        editors                       missing
CHANGES.txt       examples                      protobuf-lite.pc
config.guess      generate_descriptor_proto.sh  protobuf-lite.pc.in
config.h          gtest                         protobuf.pc
config.h.in       install-sh                    protobuf.pc.in
config.log        INSTALL.txt                   python
config.status     java                          README.txt
config.sub        libtool                       src
configure         ltmain.sh                     stamp-h1
configure.ac      m4                            vsprojects
CONTRIBUTORS.txt  Makefile
COPYING.txt       Makefile.am
Run Code Online (Sandbox Code Playgroud)

我不需要二进制文件.

c++ protocol-buffers

8
推荐指数
1
解决办法
3万
查看次数

为对象分配值时为什么调用构造函数和析构函数

我有以下代码:

#include <iostream>

using namespace std;

class A{
    int x;
public:
    A(int x =1) : x(x) {cout << "A() ";}
    A(const A& a) {x =a.x; cout << "A(const A&) ";}
    A& operator=(const A& a){cout << "op= "; x=a.x; return *this;}
    ~A(){cout << "~A()";}
    int getX() {return x;}
    void setX(int x){this->x = x;}
};


A g(A a){
    //a = 2;
    cout << "g() ";
    a.setX(3);
    return a;
}

int main()
{
    A a;
    a = 2;

}
Run Code Online (Sandbox Code Playgroud)

我期望有以下输出:A() op= ~A() …

c++ constructor destructor assignment-operator

2
推荐指数
1
解决办法
61
查看次数

使用getaddrinfo和bind发送具有固定源端口号的UDP数据包

使用BJ的talker.c代码作为模板: http://beej.us/guide/bgnet/examples/talker.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#define SERVERPORT "4950"    // the port users will be connecting to

int main(int argc, char *argv[])
{
    int sockfd;
    struct addrinfo hints, *servinfo, *p;
    int rv;
    int numbytes;
    struct sockaddr_storage their_addr;
    socklen_t addr_len;
    addr_len = sizeof their_addr;

    if (argc != 3) {
        fprintf(stderr,"usage: talker hostname message\n");
        exit(1);
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_DGRAM; …
Run Code Online (Sandbox Code Playgroud)

c sockets udp bind getaddrinfo

1
推荐指数
1
解决办法
5223
查看次数