简体   繁体   English

C ++为什么要使用从(std :: string)到(void)类型的隐式转换?

[英]C++ Why use an implicit conversion from (std::string) to (void) type?

I'm looking at CPP-NETLIB's source code and came across this syntax where it describes the concepts. 我正在查看CPP-NETLIB的源代码,并且遇到了这种语法,它描述了这些概念。

template <class R> struct ClientRequest : network::Message<R> {
  BOOST_CONCEPT_USAGE(ClientRequest) {
    std::string tmp;
    R request_(tmp);
    swap(request, request_);  // swappable via ADL

    std::string host_ = host(request);
    boost::uint16_t port_ = port(request);
    std::string path_ = path(request);
    std::string query_ = query(request);
    std::string anchor_ = anchor(request);
    std::string protocol_ = protocol(request);

    request << uri(std::string());

    network::http::uri(request, std::string());

    (void) host_;
    (void) port_;
    (void) path_;
    (void) query_;
    (void) anchor_;
    (void) protocol_;
  }

 private:
  R request;
};

I can't seem to find any explanations that describe how the (void) conversion of in-scope types could be necessary or what it would do. 我似乎无法找到任何解释,描述范围内类型的(无效)转换是如何必要的或它将做什么。 Why would you need to clear the stack before ending the BOOST_CONCEPT_USAGE member function? 为什么在结束BOOST_CONCEPT_USAGE成员函数之前需要清除堆栈? What else would it do if not clearing the stack? 如果不清除堆栈还会怎么做?

It's just for suppressing the compiler's warnings about unused variable, nothing special. 它只是用于抑制编译器有关未使用变量的警告,没有什么特别之处。

It does NOT clear the stack in any way, if that's what you mean. 如果这就是你的意思,它不会以任何方式清除堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM