在我的程序中,十六进制数除以十,其余部分被检查.
第一师表现良好; 然而,在第二次分裂后,程序出错了.我是装配新手,我找不到问题所在......
这是代码段:
ORG 1000
MOV AX, 0x04B4 (1204 decimal value )
MOV BX, 0x000A ( 10 decimal value )
MOV CX, 0x0000
DIV BX ( After this part, AX is 120 decimal and DX 4 decimal )
CMP DX, 0x0000
JE eq1
ADD CX, 0x0002
JMP con1
eq1: ADD CX, 0x0001
con1:
DIV BX ( But, after this division AX becomes 6677 ( 26231 decimal and DX remains 4 decimal )
CMP DX, 0x0000
Run Code Online (Sandbox Code Playgroud)
感谢帮助!
我正在尝试在工厂设计模式中使用智能指针。我进行了谷歌搜索以获得一些想法,但找不到任何类型的实现,但有很多很棒的想法。所以,我写了自己的代码,但有两点我不确定。
首先,我将添加我的代码,然后提出我的问题。
// AgentGameStyleFactory.hpp
#ifndef AgentGameStyleFactory_hpp
#define AgentGameStyleFactory_hpp
#include "AgentGameStyle.hpp"
#include <memory>
class AgentGameStyleFactory
{
public:
static std::unique_ptr<AgentGameStyle> instantiate(const AgentPlayingStyleData::ePLAYING_CHARACTER pStyle);
private:
static AgentGameStyle* instantiateHelper(const AgentPlayingStyleData::ePLAYING_CHARACTER pStyle);
};
#endif /* AgentGameStyleFactory_hpp */
Run Code Online (Sandbox Code Playgroud)
// AgentGameStyleFactory.cpp
#include "AgentGameStyleFactory.hpp"
using namespace AgentPlayingStyleData;
std::unique_ptr<AgentGameStyle> AgentGameStyleFactory::instantiate(const ePLAYING_CHARACTER pStyle)
{
std::unique_ptr<AgentGameStyle> newStyle( instantiateHelper(pStyle) );
return std::move(newStyle);
}
AgentGameStyle* AgentGameStyleFactory::instantiateHelper(const ePLAYING_CHARACTER pStyle)
{
AgentGameStyle* newStyle = NULL;
switch(pStyle)
{
case ePLAYING_CHARACTER::ePC_CONTAIN:
newStyle = new ContainGameStyleAgent();
break;
case ePLAYING_CHARACTER::ePC_COUNTER:
newStyle = new CounterGameStyleAgent();
break;
case ePLAYING_CHARACTER::ePC_STANDARD:
newStyle = …Run Code Online (Sandbox Code Playgroud) 我试图从文件中读取着色器字符串; 但是,我遇到了glShaderSource()功能线上的问题.如你所知,glShaderSource()需要const char**,我必须声明char *从文件中读取.所以,我正在使用转换来转换类型.
如果我使用const_cast<const char **>,会出现形状; 但是,它的颜色有误(它应该是橙色而不是白色).如果我使用reinterpret_cast<const char**>,我的Access violation reading location 0x73726576运行时间会出错.
那么,我该如何解决这个问题呢?谢谢!
平台:Windows 7,Visual Studio 2010
代码行:
shader.glsl#version 330
in vec3 vp;
void main() {
gl_Position = vec4( vp, 1.0);
}
Run Code Online (Sandbox Code Playgroud)
主要():
/* FILE READING */
FILE* shaderFile = fopen( "shader.glsl ", "r");
int fileSize = 0;
char* vertex_shader = NULL;
//Getting File Size
fseek( shaderFile, 0, SEEK_END );
fileSize = ftell( …Run Code Online (Sandbox Code Playgroud) 我是一个初学者,使用旧数据库,其中的字符?,?,?,? 被保存,就像;;;ca ...它是带有 Phoenix 框架的 Elixir 语言。我想在代码中多次替换该字符,我有一个功能:
def convert_content(content) do
content = String.replace(content, ";;;ca", "?")
content = String.replace(content, ";;;ea", "?")
content = String.replace(content, ";;;d1", "?")
content = String.replace(content, ";;;f1", "?")
end
Run Code Online (Sandbox Code Playgroud)
但它很慢..我找到了https://github.com/elixir-lang/elixir/pull/4474但它不起作用。感谢帮助。
我希望你帮我解决决定问题.
我是一个新手视频游戏程序员.我可以开发Flash,Unity,Android游戏,我知道一点CryEngine.此外,我希望将来开发3D视频游戏.
所以,我决定学习一个可以使用C/C++的视频游戏库.但我应该学习Allegro或OpenGL还是不同的图书馆?或者我应该直接开始学习DirectX编程?学习Allegro编程是有用的(一个很好的基础)还是浪费时间?
我使用具有一些虚方法的父类.当我调用虚拟方法在构造函数中,它提供了LNK2019与LNK1120以"错误error LNK2019: unresolved external symbol "protected: virtual int ... referenced in function "public: __thiscall ..."和" ...\Debug\8puzzleProject.exe : fatal error LNK1120: 1 unresolved externals"的消息.
有没有办法解决这个问题,或者我不是在构造函数中调用虚方法?
谢谢!
这是代码:
有错误的类:
#ifndef HEURISTICSEARCH_H
#define HEURISTICSEARCH_H
#include "BruteSearch.h"
class HeuristicSearch: public BruteSearch
{
public:
HeuristicSearch( int initial[BOARD_LIMIT][BOARD_LIMIT] );
bool search();
protected:
virtual int calculateUtility() = 0;
virtual int calculateUtility( Node* ) = 0;
bool check4Goal();
void checkNmove();
int findMin(int* values );
int utilityCost;
};
#endif
HeuristicSearch::HeuristicSearch( int initial[BOARD_LIMIT][BOARD_LIMIT] …Run Code Online (Sandbox Code Playgroud) 我正在开发一个template Subject class将用作某些事件驱动编程的基类。目前,我正在进行回调注册,并且我Template argument for template type parameter must be a type; did you forget 'typename'?在 行收到了“” std::map。
我觉得答案与此链接相关,但我无法形成它来解决我的问题。
这是类的标题Subject:
#ifndef Subject_hpp
#define Subject_hpp
#include "Observer.hpp"
#include <list>
#include <map>
template<class T>
class Subject
{
public:
Subject();
virtual ~Subject();
virtual void attach( Observer* const object, void(Observer::* const func)(T) );
virtual void detach(const int pObserverId);
virtual void notify(T& pEvent);
// Clear the subject: Clear the attached observer list
void clear();
private:
std::list< …Run Code Online (Sandbox Code Playgroud) 我正在使用std::stack一个项目,我需要在它上面检查相同的值.我检查了成员函数但是,我找不到适合这个任务的函数.
提出的第一个想法是使用复制堆栈但是,在这种情况下,程序可能会浪费大量额外空间,并且在项目的这个级别上不使用用户定义的堆栈类很重要(是的,我犯了一个设计错误......)
那么,任何想法?
谢谢!
我正在开发一个光线追踪项目。所以,我有很多向量操作。对于产品操作,我使用了运算符重载,遇到了一个问题。您可以在下面查看详细信息:
这些函数在一个名为 RayMath.h
//GENERAL INLINES
inline Vector operator*( float c, const Vector& v){ return v * c; } //Func1
inline Vector operator*( const Vector& v1, Vector& v2 ) { return Vector( v1.x * v2.x, v1.y * v2.y, v1.z * v2.z ); } //Func 2
Run Code Online (Sandbox Code Playgroud)
如果我添加Func 2,它会C2666, more than one operator为使用Func1. 如果我不添加Func 2,则会出现no operator matches错误。下面是使用示例:
这些行在一个.cpp名为Renderer.cpp
Vector R = ray.direction - 2.f * Dot( ray.direction, N ) * …Run Code Online (Sandbox Code Playgroud) 我正在处理一个树结构,它具有unique pointers作为类成员的向量.在研究它时,我意识到如果唯一指针所拥有的对象作为参数,我不确定如何将唯一指针初始化为类成员.
所以,我只是问:如果将拥有的对象作为参数,我应该如何将唯一指针初始化为类成员?
我应该使用new(addTheObject(new Object()))然后使用std::make_unique吗?我应该将对象作为unique_ptr(addTheObject(std::unique_ptr<Object>& theObject))传递并使用std::move(theObject)吗?
处理这个问题的正确方法是什么?
如果你需要更具体的例子:
我有一个DT_Node类,它是树的一个节点,我将使用构造一个树DT_Node.
DT_Node有一个被调用的方法addChild()用于将子元素插入其节点向量中.
DT_Node将在不同的cpp文件中用于构造树,这意味着另一个cpp文件将使用addChild()方法来添加节点的子节点.
// DT_Node.hpp
class DT_Node
{
public:
DT_Node();
virtual ~DT_Node();
virtual void decide() = 0;
virtual void addChild( ??? );
private:
std::vector< std::unique_ptr<DT_Node> > mNodes;
};
Run Code Online (Sandbox Code Playgroud)
// DT_Node.cpp
DT_Node::DT_Node()
{
}
DT_Node::~DT_Node()
{
mNodes.clear();
}
void DT_Node::addChild( ??? )
{
???
}
Run Code Online (Sandbox Code Playgroud) 我不知道为什么,但这行代码给出了一个NullPointerException.我搜索了创建用户obj的数组.在Java中,但是,我找不到任何问题.
private State[] states;
.
.
.
private void initializeStates( )
{
states = new State[ stateNames.length ]; // Throws NullPointerException
for( int i = 0; i < stateNames.length; i++ )
{
states[i] = new State();
states[i].setName( stateNames[i] );
states[i].setColor( stateColors.getColor() );
}
} // End of initializeStates()
Run Code Online (Sandbox Code Playgroud)
这是班级:
public class State
{
private String stateName;
private String color;
private boolean isStartState;
private boolean isFinalState;
State()
{
stateName = new String(); // Can this line cause nullPtrException?
color …Run Code Online (Sandbox Code Playgroud)