我正在用eclipe编写一些C++代码.
我对矢量对象有一种奇怪的行为.
当我使用该方法时resize,Eclipse返回以下错误:
#include "vector"
...
vector<int> a;
a.resize(5);
Error: Invalid arguments candidates are: void resize(?, int).
Run Code Online (Sandbox Code Playgroud)
但是代码从命令行编译.
我怎样才能解决这个日食的挑剔行为?
我正在使用以下代码来检索类的名称:
template <typename T>
string GetName(const T& object) {
using type = typename remove_const<typename remove_reference<decltype(object)>::type>::type;
return boost::typeindex::type_id_with_cvr<type>().pretty_name();
}
Run Code Online (Sandbox Code Playgroud)
代码效果很好.但是,返回的字符串也包含名称空间.是否有一个只返回类名的boost函数?我知道我自己可以写它,关键是不要重新发明轮子.
我从C++开始,我有一个疑问:
我正在创建一个函数,它将返回一个类对象的向量MyClass.
vector<MyClass>* myMethod()
Run Code Online (Sandbox Code Playgroud)
第一个问题是,返回一个指针是正确的吗?
第二个问题是:如果我要返回一个指针,我还应该将MyClass对象的指针插入向量吗?
MyClass* object;
myVector.push_back(*object);
Run Code Online (Sandbox Code Playgroud) 我在github上有一个帐户,我是一个组织的所有者.
我不明白为什么当我'git commit'然后'git push'时,网页显示组织的名称作为提交的作者.
当我运行'git push'时,我使用我的帐户的用户名和密码.
谢谢
在我的新macbook pro上使用osx lion和XCode 4.1我在使用gcc时遇到了一些问题.
在/usr/bin我找不到gcc-4.2
我只有以下版本:
i686-apple-darwin11-llvm-gcc-4.2
llvm-gcc
llvm-gcc-4.2
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试通过port select --set gcc gcc42它选择gcc42 时返回以下错误:
Selecting 'gcc42' for 'gcc' failed: could not create new link "/opt/local/bin/gcc": target "/usr/bin/gcc-4.2" doesn't exist
但是port select gcc返回以下版本:
apple-gcc42
gcc42
llvm-gcc42 (active)
mp-gcc44
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
谢谢!
我想等待一段时间的条件.我读了升压文件和它似乎是最好使用功能wait_for与谓词,如所描述这里.
不幸的是,这个例子对我来说并不是很有用.我该如何编写谓词?我试着编写上面报告的代码但是visual studio编译器抱怨:c:\boost\boost\thread\win32\condition_variable.hpp(394): error C2064: term does not evaluate to a function taking 0 arguments
这是代码的一部分:
class MyClass{
boost::mutex mutex;
boost::condition_variable myCondition;
//...
void foo();
bool myPredicate();
}
void MyClass::foo(){
boost::unique_lock<boost::mutex> lock(mutex);
boost::chrono::microseconds period(25000);
// ...
boost::chrono::system_clock::time_point wakeUpTime = boost::chrono::system_clock::now() + period;
if(myCondition.wait_until(lock,wakeUpTime,MyClass::myPredicate) == true){/...}
}
bool MyClass::myPredicate(){
if(...)
return true;
else
return true;
}
Run Code Online (Sandbox Code Playgroud)
使用wait_for谓词的正确方法是什么?
我有一个使用Qt5的项目,并且有一个CMakeLists.txt用于创建Visual Studio解决方案的文件。
这是我的摘录 CMakeLists.txt
cmake_policy(SET CMP0020 NEW)
set(CMAKE_AUTOMOC ON)
find_package(Qt5 REQUIRED COMPONENTS core widgets)
set(COMMON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src)
include_directories( ${Boost_INCLUDE_DIRS}
${COMMON_INCLUDE_DIR}
)
file(GLOB_RECURSE COMMON_SOURCE "*.hpp" "*.cpp")
add_library(${PROJECT_NAME} ${COMMON_SOURCE})
qt5_use_modules(${PROJECT_NAME} Widgets)
Run Code Online (Sandbox Code Playgroud)
当我尝试编译代码时,它返回以下错误:
>AUTOMOC : error : C:/Users/.../Projects/MyProject/build/MyProjects_automoc.cpp The file includes the moc file "moc_MyFile.cpp", but could not find header "MyFile{.h,.hh,.h++,.hm,.hpp,.hxx,.in,.txx}" in C:/Users/.../Projects/MyProject/build/
Run Code Online (Sandbox Code Playgroud)
moc文件已自动生成,并且标题不在build文件夹中,而是在src目录中的文件夹中。
如何解决此错误?
我正在为Mountain Lion开发Eclipse Juno插件.
我可以通过run as> 来测试我的插件没有问题Eclipse application.
但是,当我尝试通过执行以下操作导出插件时,它会失败.
plugin.xmlOverviewExport Wizard它返回以下错误:
/Users/luca/Documents/University/PhD/FODA/.metadata/.plugins/org.eclipse.pde.core/temp/org.eclipse.pde.container.feature/compile.org.eclipse.pde.container.feature.xml:4: The following error occurred while executing this line:
/Users/luca/Documents/University/PhD/FODA/it.unibg.robotics.featuremodels.model/build.xml:31: /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/Classes does not exist.
The following error occurred while executing this line:
/Users/luca/Documents/University/PhD/FODA/it.unibg.robotics.featuremodels.model/build.xml:31: /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/Classes does not exist.
Run Code Online (Sandbox Code Playgroud)
有什么问题?
我用这种方式定义了一个地图:
map<unsigned int, map<unsigned int, std::shared_ptr<MyObject>>> map;
Run Code Online (Sandbox Code Playgroud)
第一张地图预先初始化了一些键和空地图(内部地图).
我有一段用这张地图操作的代码:
for(auto mapElement : map){
//cout << "1) " << mapElement.second.size() << endl;
if(mapElement.second.size()>0){
// do something
}
mapElement.second.clear();
cout << "2) " << mapElement.second.size() << endl;
}
for(auto mapElement : overwrittenMsgs){
cout << "3) " << mapElement.second.size() << endl;
}
Run Code Online (Sandbox Code Playgroud)
这是一次迭代的可能输出:
1) 2
2) 0
1) 1
2) 0
3) 2
3) 1
Run Code Online (Sandbox Code Playgroud)
所以它似乎clear()并没有真正起作用.
我可以通过更换解决这个问题mapElement.second.clear();有map.at(mapElement.first).clear();.
这种行为的原因是什么?
我有一个使用std :: map的循环模式.
我只想在键存在时检索值,否则我不想插入元素.目前我正在使用count(key)或find(key)(哪一个更好?从文档中复杂性似乎是相同的),如果它们返回一个正值,我访问地图.但是我想避免在地图上使用两个操作.就像是:
map<string, int> myMap;
int returnvalue;
boole result = myMap.get("key1",returnValue)
if(result){
\\ use returnValue
}
Run Code Online (Sandbox Code Playgroud)
阅读cplusplus.com上的std :: map文档我找到了两个访问地图元素的函数:
他们都不满足我的需要.
我想创建一个可以在画布上绘制路径的应用程序.问题是我必须不断更新这个画布.
目前我能够做到,但我必须每次重绘所有路径,所以我必须将所有点存储在内存中.我更愿意通过添加新点来简单地更新绘图.
可能吗?
目前我的代码是:
public class MyCanvas extends Canvas{
private static final long serialVersionUID = 1L;
public MyCanvas(){}
public void paint(Graphics graphics){
super.paint(graphics);
graphics.setColor(Color.green);
// points is an ArrayList of Point2D
for (Iterator iterator = points.iterator(); iterator.hasNext();) {
Point2D point2d = (Point2D) iterator.next();
graphics.fillOval((int)((canvas.getWidth()/2.0) + point2d.getX()), (int)((canvas.getHeight()/2.0) + point2d.getY()), 5, 5);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑
这是目前的解决方案:
PanelCanvas canvasPanel;
...
public void drawCircle(int x, int y){
Graphics2D g2d = bufferedImage.createGraphics();
g2d.setColor(Color.green);
g2d.setBackground(Color.white);
g2d.fillOval((int)((panelCanvas.getWidth() / 2.0) + x/10.0), (int)((panelCanvas.getHeight() / 2.0) …Run Code Online (Sandbox Code Playgroud)