Shape.h
namespace Graphics {
class Shape {
public:
virtual void Render(Point point) {};
};
}
Run Code Online (Sandbox Code Playgroud)
Rect.h
namespace Graphics {
class Rect : public Shape {
public:
Rect(float x, float y);
Rect();
void setSize(float x, float y);
virtual void Render(Point point);
private:
float sizeX;
float sizeY;
};
}
struct ShapePointPair {
Shape shape;
Point location;
};
Run Code Online (Sandbox Code Playgroud)
像这样使用:
std::vector<Graphics::ShapePointPair> theShapes = theSurface.getList();
for(int i = 0; i < theShapes.size(); i++) {
theShapes[i].shape.Render(theShapes[i].location);
}
Run Code Online (Sandbox Code Playgroud)
这段代码最终会调用Shape::Render
而不是Rect::Render
我假设这是因为它正在施放Rect
到a Shape
,但我不知道如何阻止它这样做.我试图通过重写 …
我想让我的代码更快地运行,以进行更多的迭代和运行。现在,我的代码太慢了,但是我不知道要更改什么来加速它。我首先编写了动力学的蒙特卡洛模拟,然后将其编辑为布朗运动模拟。我当前的代码无法处理10,000次运行,每次运行10,000次迭代。
import numpy as np
import matplotlib.pyplot as plt
import time
%matplotlib inline
runs = int(input("Enter number of runs: "))
N = int(input("Enter number of iterations per simulation: "))
y = 0
R = 10*1 # R is the rate value
t0 = time.time()
for y in range(runs): # Run the simulation 'runs' times
T = np.array([0])
dt = 0
x = 0.5 # sets values
X = np.array([x])
t = 0
i = 0
while t < N: # …
Run Code Online (Sandbox Code Playgroud) return;
in a void
function. What does it actually do?
void function() {
if(x==NULL) {
return;
}
else{
/////
}
}
Run Code Online (Sandbox Code Playgroud)