C++ 不使用push_back命名类型
我不熟悉使用c语言++ 当我执行以下代码时 我知道它现在不应该画任何东西,我只是想从使用数组作为顶点位置改为使用向量,因为我希望能够计算点,然后使用push_向后追加它们 此最小示例不会编译:C++ 不使用push_back命名类型,c++,C++,我不熟悉使用c语言++ 当我执行以下代码时 我知道它现在不应该画任何东西,我只是想从使用数组作为顶点位置改为使用向量,因为我希望能够计算点,然后使用push_向后追加它们 此最小示例不会编译: #include <vector> std::vector<float> vertexPositions; const float triangle = 0.75f; vertexPositions.push_back(triangle); int main(int arg
#include <vector>
std::vector<float> vertexPositions;
const float triangle = 0.75f;
vertexPositions.push_back(triangle);
int main(int argc, char** argv)
{
return 0;
}
是否添加了include?我看到了您的问题-以下行必须出现在主函数中:
vertexPositions.push_back(triangle);
我创建了一个控制台应用程序作为示例:
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<float> vertexPositions;
const float triangle = 0.75f;
vertexPositions.push_back(triangle);
return 0;
}
有什么简单的东西你可能会错过吗?vertexPositions.push\u backtriangle;这是一份声明。它必须放在函数定义中。它不能像那样被放在全局范围内
将该行移到例如main中,您应该不会有问题。请显示一个完整的示例;这个代码在单独的情况下看起来还可以。嗯,你需要那个代码,至少在main中调用push_back.+1。鉴于他/她发布的代码,这是唯一可能的错误;b常量浮动三角形=0.75f;要么是陈述。对于在全局范围内可行的语句是否有特殊的表示?Cheesok,函数调用是一个表达式,请参见
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<float> vertexPositions;
const float triangle = 0.75f;
vertexPositions.push_back(triangle);
return 0;
}