我是C ++的新手。我正在尝试修改一个非常复杂的视频编解码器代码作为我最后一年学校项目的一部分。这是我的代码:
这是我已声明三个外部变量的头文件: yuv.h
#include <vector>
namespace X265_NS
{
extern int frameNumber;
extern int frameSize;
extern std::vector<int>numbers;
class YUVInput : public InputFile, public Thread
{
protected:
// some more variables
public:
// more variables and function declarations
};
}
这是第一个使用这些extern变量的文件: yuv.cpp
#include "yuv.h"
//more includes
#include <vector>
using namespace X265_NS;
int frameNumber;
int frameSize;
std::vector<int>numbers;
// some stuff and function calls
// here I use my extern variables in a function
frameNumber = readCount.get();
frameSize = ceil((double)height / 32) * ceil((double)width / 32);
//more stuff
bool YUVInput::populateFrameQueue()
{
if(read<1)
{
ifstream file("/home/abu-bakr/bin/test.txt");
int number;
while (file >> number)
numbers.push_back(number);
}
}
// more stuff
这是我使用这些外部变量的第二个类:
analysis.cpp
#include "yuv.h"
#include <vector>
....
using namespace X265_NS;
// some stuff
// its in a function and only place where I am using these variables
int qp_ctu = numbers.at((ctu.m_cuAddr + 1) + (frameSize*(frameNumber - 1)));
// more stuff
我想知道:
答案 0 :(得分:1)
问题出在你的yuv.cpp
中<html>
<head>
<title>My first three.js app</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="https://rawgithub.com/mrdoob/three.js/master/build/three.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 500);
camera.position.set(0, 10, 100);
camera.lookAt(new THREE.Vector3(0, 0, 0));
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var material = new THREE.LineBasicMaterial({ color: 0x0000ff });
var geometry = new THREE.Geometry();
var a = 5;
geometry.vertices.push(new THREE.Vector3(-a, 0, 0));
geometry.vertices.push(new THREE.Vector3(0, a, 0));
geometry.vertices.push(new THREE.Vector3(a, 0, 0));
geometry.vertices.push(new THREE.Vector3(0, 0, -a));
var line = new THREE.Line(geometry, material);
scene.add(line);
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABISURBVDhPzc1bCgAgCETR9r9poxynEHoIEp0vLS4WCWpBMfq09yYI8QFuTfBhlgFXHSgj4KB0pYzAwYfx+9FVgFv92ifBIFIBJq9zqYwecEQAAAAASUVORK5CYII=";
var loader = new THREE.TextureLoader();
var spriteMaterial = new THREE.SpriteMaterial( { color: 0x00ff00 } );
var spriteMaterial;
loader.load(img,
function(texture)
{
spriteMaterial.map = texture;
spriteMaterial.needsUpdate = true;
}
);
var sprite = new THREE.Sprite( spriteMaterial );
sprite.scale.set(6, 6, 1);
sprite.position.set( 0, 6, -6 );
scene.add( sprite );
var render = function () {
requestAnimationFrame( render );
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>
这些定义属于using namespace X265_NS;
int frameNumber;
int frameSize;
和::frameNumber
,与::frameSize
和X265_NS::frameNumber
不同。
将上述内容更改为
X265_NS::frameSize
或
namespace X265_NS {
int frameNumber;
int frameSize;
}
using namespace X265_NS; // for subsequent code that uses those variables