我的测试代码有问题.它编译得很好,但是当我尝试调用delegate时,程序崩溃了.
#include "..\libs\FastDelegate\FastDelegate.h"
#include <string>
#include <map>
#include <iostream>
typedef fastdelegate::FastDelegate1 <int, int> FuncPtr;
struct Function
{
FuncPtr Ptr;
int Param;
Function() {};
Function (FuncPtr Ptr_, int Param_): Ptr (Ptr_), Param (Param_) {};
int operator() (int xxx) {return Ptr(xxx);};
};
std::map <std::string, Function> ExternalFuncs;
bool RegisterFunction (const std::string& a, const Function b)
{
ExternalFuncs[a] = b;
return true;
}
int foo (int bar)
{
std::cout << "Jest gites";
return 0;
}
int main()
{
RegisterFunction ("Foo", Function(&foo, 1));
ExternalFuncs ["foo"] …Run Code Online (Sandbox Code Playgroud) 我在这个项目上工作,
我遇到的问题是,当我需要它时,它并没有真正被删除,因为它有一些指向它的共享指针.
我该如何解决这个问题,请帮忙.
为什么在Bellman ford算法中允许负边循环而在dijkstra算法中不允许负边?
比较的运算符(<=,>,==等)你通常将它们作为基本运算符实现,你可以在使用之后实现其余的比较运算符或者在类之间进行所有可能的比较?
我有所有vc80以例如命名的boost库- libboost_serialization-vc80-mt-1_42但编译器正在寻找libboost_serialization-vc100-mt-1_42我需要重新下载库vc100吗?
这是我的问题.我正在以二进制模式读取文件,将字节附加到int数组,然后打印值.我的问题是,当我结果我的结果时,随机字符被附加在流中.
comp.txt:
this text is a testt1
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
void read(ifstream& stream, unsigned int buf[], int size)
{
for(int i = 0; i < size; ++i)
{
unsigned char temp[4] = {'\0', '\0', '\0', '\0'};
stream.read((char*)temp, 4);
cout << "Temp: " << temp << '\n';
buf[i] = *((int*)temp);
cout << "Read: " << buf[i] << endl;
memset(temp, '\0', 4);
}
}
int main()
{
// open file
ifstream f;
f.open("comp.txt", ios::binary);
cout …Run Code Online (Sandbox Code Playgroud) A.h
class A
{
private:
static const int b = 50;
int c[b];
};
A.cpp
#include "A.h"
const int A::b;
C.cpp
#include "A.h"
Run Code Online (Sandbox Code Playgroud)
编译器向我发出警告,说b多次定义,一个被忽略.我需要在类中定义它,因为我需要初始化数组.或者,我需要使用枚举方法来做到这一点.但我想知道这是否可行?
请参阅以下代码以更好地理解我的问题.
class compareByValue {
public:
bool operator()(const string* s1, const string* s2) const
{
if (s1 == s2)
return true;
if ((s1==NULL) || (s2==NULL))
return false;
return (0 == s1->compare(s2->c_str()));
}
};
map<string*, string*, compareByValue> nodeIdToIpAddress;
for (int i = 0; i < nrec; ++i) {
nodeIdToIpAddress[ptr1[i]] = ptr2[i];
cout << "Added " << *(ptr1[i]) << " , " << *(ptr2[i]) << endl;
}
cout << "map has " << nodeIdToIpAddress.size() << " elements!" << endl;
Run Code Online (Sandbox Code Playgroud)
我有一个地图,维护键,值对,它们是指向字符串对象的指针.我确信键和值都不是NULL指针.当我运行上面的程序(好吧,我跳过周围的代码以使其更容易理解),"添加......"被打印49次.ptr1 [i],ptr2 [i]是字符串对象的指针,不是NULL指针,因为我的程序不会发生段错误.
我遇到的问题是,当我在最后打印地图的大小时,它表示地图中只有1个元素. …
我的C++代码中的#define语句有些问题,但是我不熟悉如何在VC++中处理它:
>filetaint.cpp
1>.\filetaint.cpp(272) : error C2872: 'UINT32' : ambiguous symbol
1> could be 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\\include\basetsd.h(82) : unsigned int WIND::UINT32'
1> or '..\..\include\gen\types_foundation.TLH(80) : LEVEL_BASE::UINT32'
1>.\filetaint.cpp(275) : error C2872: 'UINT32' : ambiguous symbol
1> could be 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\\include\basetsd.h(82) : unsigned
[...]
Run Code Online (Sandbox Code Playgroud)
==========构建:0成功,1失败,0最新,0跳过==========
所以问题在于,编译器不知道是否使用我的Windows SDK"basetsh.h"或者types_foundation.h中的定义.我希望它使用后者.在C++命名空间中是否有任何构造来告诉编译器选择什么?我想避免修补SDK或库本身.
#include "filetaint.h"
#include "dift.h"
using namespace WIND;
Run Code Online (Sandbox Code Playgroud)
types_foundation.TLH包含正确的语句.它已经在VS 2008中的VC++路径中了.我在这里有点困惑......但我想我必须找到一种方法告诉我的编译器暂时忽略SDK;).
我不知道为什么会这样; 一些谷歌搜索让我相信它是由于不正确的内存管理,而其他人则说这是因为链接到可执行文件的无效.DLL.我似乎无法解决这个问题,因为我能想到的唯一.DLL是无效的.我的freeglut .DLL,但它本身没有任何问题.
我要做的就是创建一个窗口.
题
我的代码发生了什么?我做错了什么,我该如何解决?
码
WinMain
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow) {
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
bool done;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszClassName = L"someclass";
if (!RegisterClassEx(&wc)) { //Error:
MessageBox(NULL, L"Class registration has failed!", L"Error!", MB_OK | MB_ICONINFORMATION);
return 0;
}
hwnd = …Run Code Online (Sandbox Code Playgroud) c++ ×9
visual-c++ ×3
stl ×2
algorithm ×1
boost ×1
crash ×1
delegates ×1
dijkstra ×1
graph ×1
map ×1
namespaces ×1
shared-ptr ×1
winapi ×1