我一直在尝试进行前向声明以允许类之间的访问.我在这里读到:
在前向声明期间,我无法找到很多名称空间.我相当肯定我搞砸了(我只是不知道把它们放在哪里).我得到的错误是在相关代码片段之后.
这就是我做的:
我已将我的类定义从.h分割为.cpp和.h
我的.h文件中有#ifndef警卫
这些是我的文件:
Form1.cpp
#include "stdafx.h"
#include "OpenGL.h"
#include "Form1.h"
#include "serialcom.h"
#include "calculations.h"
using namespace GUI_1;
GUI_1::Form1::Form1(void)
{....
}
void GUI_1::Form1::chlabel2(float num)
{....
}
int GUI_1::Form1::updateHand(int source){....}
void GUI_1::Form1::resetHand(){....}
Run Code Online (Sandbox Code Playgroud)
Form1.cpp的错误每个定义都是一样的
error C2872: 'GUI_1' : ambiguous symbol
could be 'GUI_1'
or OpenGLForm::GUI_1'
Run Code Online (Sandbox Code Playgroud)
Form1.h
#ifndef form1
#define form1
using namespace OpenGLForm;
//error C2871: 'OpenGLForm' : a namespace with this name does not exist
ref class COpenGL;
namespace GUI_1 {
using namespace System;
using namespace …Run Code Online (Sandbox Code Playgroud) 我正在查看以下代码,并且在计算其性能时发现了一些奇怪的东西.
为了记录,我在Visual Studio 2010,Windows 7 x64,-O2优化和发布模式下执行此操作.我的处理器是Intel i5.
代码中有一个部分可以写入内存.我曾经这样做过:
d_res_matrix[x][y] = a;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,执行整个程序大约需要2.3秒.我正在试图使代码变得更快,并且我做了这个:
d_res_matrix[x][y] = a + 0.00000001;
Run Code Online (Sandbox Code Playgroud)
在0.4秒内执行!这是一个巨大的差异,但我不确定为什么会发生这种情况.
对我而言,如果它更慢,因为额外的加法操作需要时间.我想我的替代假设是,以某种方式进行添加会强制编译器对此操作进行SIMD(获取,添加和写入?).也许写入否则会阻止管道,但这可以防止这种情况?有任何想法吗?
编辑(4月6日,6:19):问题在我的家用电脑上是一样的(Visual Studio 2012).
编辑(4月6日,6:38):Visual Studio 2008中也存在该问题(-O2,发布).在Debug中,它们都很慢,但速度相同.
编辑(4月8日,1:28):我安装了英特尔Parallel Studio XE(我是一名学生),它向我展示了很多好东西 - 首先,我从未真正删除过我宣布的数组(我是现在不修理它,但要注意).但是,释放内存实际上并没有解决任何问题.正如理查德在答案中所述,整个问题是由非正规浮点值引起的(请参阅此处的更多信息).FP单元无法正确处理非正规值,而是启动微码序列,这非常慢.
#include <time.h>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#define DIM 1000
#define ITERATIONS 100
#define CPU_START clock_t t1; t1=clock();
#define CPU_END {long int final=clock()-t1; printf("CPU took %li ticks (%f seconds) \n", final, ((float)final)/CLOCKS_PER_SEC);}
int main(void)
{
double ** d_matrix, ** d_res_matrix;
d_res_matrix = new double * [DIM];
d_matrix …Run Code Online (Sandbox Code Playgroud) Visual Studio 2010(C++)中的C++ CLR.
我有这个结构:
value struct Triangle{
static array<int>^ v = gcnew array<int>(3);
static array<int>^ t = gcnew array<int>(3);
static array<int>^ n = gcnew array<int>(3);
};
Run Code Online (Sandbox Code Playgroud)
我在课堂的"私人"部分声明了以下内容:
static array<Triangle^>^ triangles = gcnew array<Triangle>(MAX_POLYGONS);
Run Code Online (Sandbox Code Playgroud)
我得到这个错误,我不知道它意味着什么(因为它似乎自相矛盾):
error C2440: 'initializing' : cannot convert from 'cli::array<Type> ^' to 'cli::array<Type> ^'
with
[
Type=Triangle
]
Run Code Online (Sandbox Code Playgroud)
显然它不喜欢结构.我应该使用ref而不是value吗?这产生了很多指针.任何推进正确的方向将不胜感激.
我想要以图片形式显示一些数据.在一种情况下,我想重新缩放x和y轴,这导致我使用imagesc.问题是相同的色图(喷射)imagesc与...相比看起来不同image.
有没有办法让它们一样?
我正在使用MATLAB R2014a.
示范:
以下是我展示它们的方式:
figure; image(cancelledmap); colormap(jet); %image
figure; imagesc(y,x,cancelledmap); colormap(jet); %imagesc
Run Code Online (Sandbox Code Playgroud)
并输出:
两个数字的颜色映射设置在某种程度上相同,但是:
我的项目最终编译成功,没有错误,但是警告“饥渴且数量众多”。例如,我有这行:
i_temp_reg <= {{SPI_WIDTH{'b0}}, i_temp_reg[BANK_DATA_WIDTH-1:SPI_WIDTH]};
Run Code Online (Sandbox Code Playgroud)
我将参数定义为:
parameter SPI_WIDTH = 8;
parameter BANK_DATA_WIDTH = 32;
Run Code Online (Sandbox Code Playgroud)
顾名思义,i_temp_reg是一个寄存器。我还有更多类似的语句(相同的格式,不同的寄存器),并且所有这些语句都会出错:
Concatenation with unsized literal; will interpret as 32 bits
Run Code Online (Sandbox Code Playgroud)
但是我认为我已经很清楚地指定了此字面量('b0)的大小。那么发生了什么,Verilog?我必须在这里说我通常使用VHDL,对此我感到很自在,这种疯狂的语言使我有点发疯。我是否弄乱了这个字面量的大小?
其次,和某种相关,我遇到了另一个问题。以下是相关声明和警告:
output [BANK_SIZE-1:0] wAddr;
reg [BANK_SIZE-1:0] i_wAddr;
assign w_Addr = i_wAddr;
Warning: Result of 4-bit expression is truncated to fit in 1-bit target.
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我准确地确定我在做什么错,我将不胜感激。
c++ ×2
c++-cli ×2
concat ×1
matlab ×1
optimization ×1
performance ×1
struct ×1
verilog ×1
winforms ×1