如果直接给std::vector<Struct> 定义时就赋值,出现:
error: could not convert ‘{{"audio", "audio/opus", 0, 48000}}’ from ‘<brace-enclosed initializer list>’ to ‘std::vector<RtpCodecCapability>’
例如下代码:
#include <vector>
#include <string>
#include <iostream>
struct RtpCodecCapability {
std::string kind;
std::string mimeType;
int preferredPayloadType = 0;
int clockRate = 0;
};
struct RtpCapabilities {
std::vector<RtpCodecCapability> codecs;
};
const RtpCapabilities supportedRtpCapabilities = {
// codecs
{
{
"audio", // kind
"audio/opus", // mimeType
0, // preferredPayloadType
48000, // clockRate
},
{
"audio", // kind
"audio/opus", // mimeType
0, // preferredPayloadType
48000, // clockRate
},
{
"audio", // kind
"audio/opus", // mimeType
0, // preferredPayloadType
48000, // clockRate
},
},
};
int main() {
std::cout << "codes size " << supportedRtpCapabilities.codecs.size() << std::endl;
return 0;
}
编译选项:g++ -std=c++11 -o main main.cpp
解决办法:
调整为c++14可以通过,g++ -std=c++14 -o main main.cpp