我有一个奇怪的问题。在一个非常简单的例子中(它是c,而不是c ++ ):
console.log('The bot is starting');
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
var billboard = require("billboard-top-100").getChart;
var stream = T.stream('user');
stream.on('follow', followed);
function followed(eventMsg){
var name = event.source.name;
var screenName = event.source.screen_name;
tweetIt();
}
function tweetEvent(eventMsg) {
var replyTo = eventMsg.in_reply_to_screen_name;
var text = eventMsg.text;
var from = eventMsg.user.screen_name;
if (replyTo == "HearBetterMusic") {
var text = ("@" + from + tweetEventComments.pickAndPad());
postTweet(text);
}
}
function tweetIt() {
var playlistId = "UUknVpWR6m2Ijzkqo-aPXs_g",
APIKey = "AIzaSyBDdHRVWmH3t_1sA0HSaK16IH_x-KsYaIo",
baseURL = "https://www.googleapis.com/youtube/v3/";
get(baseURL + "playlistItems?part=snippet&maxResults=50&playlistId=" + playlistId + "&key=" + APIKey, function(data) {
var goodSongs = playlistItems.list;
var goodSong = goodSongs[Math.floor(Math.random() * goodSongs.length)];
// Do what you want with the data
});
var popSong = billboard[Math.floor(Math.random() * billboard.length)];
console.log(popSong);
var popArtist = billboard.artist[Math.floor(Math.random() * billboard.length)];
console.log(popArtist);
var tweet = {
status: 'Dude! I cannot get away from' + popSong + '.' + popArtist + 'is the worst. Listen to' + goodSong + 'instead'
}
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log("Oh no! It didnt work");
} else {
console.log("It worked!");
}
}
}
tweetIt();
setInterval(tweetIt, 1000*60*30);
我有错误E0304:
严重级代码说明项目文件行抑制状态错误 (主动)E0304没有功能模板实例“__countof_helper” 匹配参数 列表
我没有使用visual studio 15.6.7,它出现了15.7更新。工具集没有明显改变,它仍然是:
平台工具集:Visual Studio 2017(v141)
发生了什么事?我该如何解决这个问题?
答案 0 :(得分:4)
改为使用std::size
:
#include <iterator>
int main()
{
int x[3];
auto const xs{::std::size(x)};
}
切换到std::array
,std::vector
或兼容的包装后,无需进行任何更改:
::std::array<int, 3> ax{};
auto const axs{::std::size(ax)};
::std::vector<int> vx{0, 0, 0};
auto const vxs{::std::size(vx)};
答案 1 :(得分:1)
对于没有C ++ 17编译器的人来说,这可以解决问题:
template <class T, std::size_t N>
size_t countof(const T (&array)[N])
{
return N;
}
答案 2 :(得分:1)
此错误从IntelliSense引擎报告,不会影响项目的构建。为避免IntelliSense中的烦恼,可以应用以下解决方法:
在项目中包含的vcruntime.h
中(通过_countof
使用转到定义,然后 Go,您应该能够找到正确的项目要在_crt_countof
的定义中_countof
上定义,请替换:
#if defined _M_X64 || defined _M_ARM || defined _M_ARM64
使用:
#if (defined _M_X64 || defined _M_ARM || defined _M_ARM64) && !__INTELLISENSE__
Microsot将正在进行适当的修复,因此将来不再需要解决方法。