这实际上是一个非关键问题,但是我在大多数情况下使用函数指针时都会收到此警告,但仍无法自行解决原因.考虑以下原型:
typedef void * Pointer;
void tree_destroyLineage(Tree greatest_parent, void *dataDestructor(Pointer data));
Run Code Online (Sandbox Code Playgroud)
到目前为止,我可以编译我的千行代码并获得零警告.所以我假设我正确地写了声明.但后来我在代码中调用它,将自由作为我的析构函数传递,因为存储在树节点中的数据是简单的结构:
tree_destroyLineage(decision_tree, free);
Run Code Online (Sandbox Code Playgroud)
这让我得到了一个"warning: passing argument 2 of 'tree_destroyLineage' from incompatible pointer type"信息.我的第一个假设是编译器无法在编译时弄清楚Pointer并且void *是相同的事情,所以我尝试用完全相同类型的函数指针创建另一个函数,该函数指针"重新调用"调用free()并更改函数指针声明接受void *而不是指针.这两种方法在同一个地方给了我同样的警告.
我做错了什么,如何解决?
我有一个函数从日志文件中读取行,将这些行转换为某个类并返回此类的实例的STL列表.
我应该如何声明这个函数,以便在将它归因于调用者时不复制整个列表?
不失一般性,假设:
list<Request> requests = log_manipulator.getAsRequestList();
Run Code Online (Sandbox Code Playgroud)
我该如何申报getAsRequestList()?我应该返回对列表的引用还是只返回一个列表?
这是一个严重的问题,因为在这个特定的赋值中,列表将包含大约1.5M的元素,因此这样的错误可能会增加内存使用量.
我在声明一个指向类实例的STL指针集时遇到了一些麻烦.更具体地说,我有这种情况:
class SimulatedDiskFile {
private:
// ...
public:
// ...
struct comparator {
bool operator () (SimulatedDiskFile* const& file_1, SimulatedDiskFile* const& file_2) {
return ((*file_1)->getFileName() < (*file_2)->getFileName());
}
};
}
typedef set<SimulatedDiskFile*, SimulatedDiskFile::comparator> FileSet;
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用.编译器说它没有找到成员SimulatedDiskFile :: comparator()函数.如果我把这个声明放在函数中(在struct之外),编译器说它期待一个类型.
现在这里是我的怀疑(不仅是一个,而且相关,我猜):
在发布之前我确实在许多地方查找过,但我发现这些引用令人困惑,与我的特殊情况并不完全相关(就像我认为的那样愚蠢 - 实际上,也许这就是原因).所以,任何好的链接也都有很大的帮助!
提前致谢!
(在这里插入真正基本的问题免责声明)
更具体地说,我有以下声明:
output reg icache_ram_rw
Run Code Online (Sandbox Code Playgroud)
在代码的某些方面,我需要将零值放在此reg中.这是我尝试过的和结果:
assign icache_ram_rw = 1'b0;
( declarative lvalue or port sink reg icache_ram_rw must be a wire )
icache_ram_rw <= 1'b0;
( instance gate/name for type "icache_ram_rw" expected - <= read )
Run Code Online (Sandbox Code Playgroud)
我怎么办呢?!
我有以下仿函数:
class ComparatorClass {
public:
bool operator () (SimulatedDiskFile * file_1, SimulatedDiskFile * file_2) {
string file_1_name = file_1->getFileName();
string file_2_name = file_2->getFileName();
cout << file_1_name << " and " << file_2_name << ": ";
if (file_1_name < file_2_name) {
cout << "true" << endl;
return true;
}
else {
cout << "false" << endl;
return false;
}
}
};
Run Code Online (Sandbox Code Playgroud)
它应该是一个严格的弱排序,并且它很长(可能只有一行)用于调试目的.
我正在使用这个仿函数作为stl :: set的比较器函子.问题是,它只插入第一个元素.通过将控制台输出添加到比较器功能,我了解到它实际上每次都将文件名与自身进行比较.
其他相关的是:
typedef set<SimulatedDiskFile *, ComparatorClass> FileSet;
Run Code Online (Sandbox Code Playgroud)
和
// (FileSet files_;) <- SimulatedDisk private class …Run Code Online (Sandbox Code Playgroud) 我无法使用Eclipse在托管模式(Debug as - > web application)中启动我的GWT应用程序.它抛出了标题中提到的异常.Eclipse调试向我展示了以下代码:
/*
* GOOGLE: Since we're bundling our own version of SWT, we need to be
* able to tell SWT where its dynamic libraries live. Otherwise we'd
* have to force our users to always specify a -Djava.library.path
* on the command line.
*/
String swtLibraryPath = System.getProperty ("swt.library.path");
try {
String newName = name + "-" + platform + "-" + version; //$NON-NLS-1$ //$NON-NLS-2$
if (swtLibraryPath != null)
System.load(swtLibraryPath + System.mapLibraryName(newName));
else
System.loadLibrary …Run Code Online (Sandbox Code Playgroud)