我正在迈出第一步boost python来测试我的班级,但是在为我的班级声明python模块时遇到了困难。
我的课程接受指向另一个课程的指针,但我不知道如何声明
class A{ };
class B
{
B( std::string& name, A* ptr ){
std::cot << ptr->data << std::endl; // no ownership
}
void my_foo(){
// do something!
}
};
Run Code Online (Sandbox Code Playgroud)
我将A类导出到python,但B类面临问题
class_< B >("B", init< std::string, A >() )
{
.def("my_foo", &B::my_foo);
}
Run Code Online (Sandbox Code Playgroud)
我有很多错误。我做错了什么?我正在阅读有关政策的信息,但在这里我认为我不必申请其中的一些政策,对吗?
亲切的问候
美国空军
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
int main()
{
string temp;
ifstream inFile;
ofstream outFile;
inFile.open("ZRMK Matched - 010513.txt");
outFile.open("second.txt");
while(!inFile.eof()) {
getline(inFile, temp);
if (temp != "") {
getline(inFile, temp);
outFile << temp;
}
}
cout << "Data Transfer Finished" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我很难让这个工作.当我执行程序时,它会循环一段时间,然后终止而不完成 - 它不会向输出文件输出任何文本行.任何帮助,将不胜感激.
我有一个元素是向量的映射.我必须从这些向量中删除所有等于特殊数字的元素 num
std::map<size_t,std::vector<size_t> > myMap;
for (std::map<size_t,std::vector<size_t> >::iterator itMap = myMap.begin();itMap != myMap.end();++itMap )
{
for (std::vector<size_t>::iterator itVec = itMap->second.begin();itVec != itMap->second.end();)
{
auto itNextVec = itVec;
++itNextVec;
if (*itVec == num)
{
itMap->second.erase(itVec );
}
itVec = itNextVec;
}
}
Run Code Online (Sandbox Code Playgroud)
代码会导致运行时出现.在VS - 中vector iterators incompatible.有人能说出原因是什么吗?
谢谢
我正在开发一个C++项目,我必须连接到redis数据库.我试图让credis代码工作,但是当我编译它时,我得到了这些错误集
1>c:\c++redis\credis.c(728): warning C4013: 'fcntl' undefined; assuming extern returning int
1>c:\c++redis\credis.c(728): error C2065: 'F_GETFL' : undeclared identifier
1>c:\c++redis\credis.c(729): error C2065: 'F_SETFL' : undeclared identifier
1>c:\c++redis\credis.c(729): error C2065: 'O_NONBLOCK' : undeclared identifier
1>c:\c++redis\credis.c(734): error C2065: 'EINPROGRESS' : undeclared identifier
1>c:\c++redis\credis.c(740): warning C4133: 'function' : incompatible types - from 'int *' to 'char *'
Run Code Online (Sandbox Code Playgroud)
错误在第credis.c728行到第746行的文件中
/* connect with user specified timeout */
flags = fcntl(fd, F_GETFL);
if ((rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK)) < 0) {
DEBUG("Setting …Run Code Online (Sandbox Code Playgroud) 我的理解是,当你包括c在你的头c++的项目,你必须把它包起来extern "C",因为c++和c具有识别功能的两种不同的方式.c将使用该名称来标识一个函数,并且c++必须使用名称和参数来满足函数重载.
我不明白的是,为什么有c不需要被包裹在头部extern "C"像windows.h?
我试图在另一个名为display的.h文件中调用一个函数,该文件接收一个指针,std::vector<vector<double> >但是当我尝试调用它时,我得到的错误是该范围内没有声明变量.这是代码示例,希望您能提供帮助.
//proper includes above
#include <vector>
#include "display.h"
#include "extract_balls.h"
int main(void)
{
std::vector<vector<double> > balls_centroids;
std::vector<vector<double> > balls_centroids_computed;
balls_centroids = extract_balls();
for (vector< vector<double> >::size_type u = 0; u < balls_centroids.size(); u++) {
vector<double> x = balls_centroids.at(u);
x[0] = farest_point[0]-x[0];
x[1] = farest_point[1]-x[1];
x[2] = farest_point[2]-x[2];
balls_centroids_computed.push_back(x);
}
display(&balls_centroid_computed);
}
Run Code Online (Sandbox Code Playgroud)
display.h文件是这样的:
#include <vector>
void display(std::vector<std::vector<double> >& coord){
//do stuff
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用C++创建二叉搜索树.我只使用函数来插入数据和查找数据.我似乎无法使程序工作,虽然我发现它是非常逻辑和正确的?
任何帮助将不胜感激.
#include<iostream>
using namespace std;
template <class T>
class BinarySearchTree
{
private:
struct tree
{
tree *leftchild;
tree *rightchild;
T data;
};
tree *root;
public:
BinarySearchTree()
{
root=NULL;
}
void insert(T);
void searchForItem(T);
};
template<class T>
void BinarySearchTree<T>::insert(T newNum)
{
tree *newItem = new tree;
tree *parent;
newItem->data = newNum;
newItem->leftchild = NULL;
newItem->rightchild = NULL;
if(root==NULL)
root=newItem;
else
{
tree *current;
current=root;
while(current)
{
parent = current;
if(newItem->data > current->data)
current = current->rightchild;
else
current = current->leftchild;
} …Run Code Online (Sandbox Code Playgroud)