我有一个类头文件myclass.h
#ifndef MYCLASS_H
#define MYCLASS_H
#include <iostream>
#include <math.h>
#include <vector>
#include <vtkSmartPointer.h>
#include <vtkMatrix4x4.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv/cv.h>
class myclass
{
public:
double compute(vtkMatrix4x4 *transMat, std::vector<Point3f>* sourcePoints);
};
#endif // MYCLASS_H
我的myclass.cpp是:
#include <myclass.h>
#include <iostream>
#include <math.h>
#include <vector>
#include <vtkSmartPointer.h>
#include <vtkMatrix4x4.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv/cv.h>
using namespace std;
double myclass::compute(vtkMatrix4x4 *transMat, std::vector<Point3f>* sourcePoints)
{
double x;
......code for computing x......
................................
return x;
}
执行时会返回错误:
myclass myFunctions;
std::vector<cv::Point3f> sourcePoints;
vtkSmartPointer<vtkMatrix4x4> mat = vtkSmartPointer<vtkMatrix4x4>::New();
...........mat and sourcePoints filled..................
double c = myFunctions.compute(mat, sourcePoints);
我应该将vtkMatrix和sourcePoints声明为头文件中的私有属性吗?我被困在这一点上。
答案 0 :(得分:2)
class myclass
{
public:
double myclass::compute(vtkSmartPointer<vtkMatrix4x4> mat, const std::vector<Point3f>& sourcePoints)
};
double myclass::compute(vtkSmartPointer<vtkMatrix4x4> mat, const std::vector<Point3f>& sourcePoints)
{
double x;
......code for computing x......
................................
return x;
}
// now you can call it in the desired way:
myclass myFunctions;
std::vector<cv::Point3f> sourcePoints;
vtkSmartPointer<vtkMatrix4x4> mat = vtkSmartPointer<vtkMatrix4x4>::New();
double c = myFunctions.compute(mat, sourcePoints);