cant compile class in seperpate .h/.cpp files

I am just now learning how to split class accross .cpp & .h. I've come across an error during this & can't compile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
.cpp

#include "stdafx.h"
#include "camera_param.h"
#include <iostream>
#include "opencv2/features2d/features2d.hpp"
#include "ArduCamlib.h"
#include "camera_param.h"

using namespace std;
using namespace cv;

camera_param::camera_param()
{
	std::cout << "camera_param constructor called" << std::endl;
}
void camera_param::set_cam_vars(cv::SimpleBlobDetector::Params)
{
}


.h

1
2
3
4
5
6
7
8
9
class camera_param
{
public:
	camera_param();

	void set_cam_vars(cv::SimpleBlobDetector::Params);
	~camera_param();
	
};


main.cpp

1
2
3
4
5
//cam_params.print_setting(99);
	SimpleBlobDetector::Params params1;
	std::cout << "lets set params1" << std::endl;
	set_blob_detector_settings(params1); //ok
	camera_param cp; //try instantiation 


errors:

'void camera_param::set_cam_vars(cv::SimpleBlobDetector::Params)': overloaded member function not found in 'camera_param' ArduCam_test c:\users\clang\desktop\working folder\opencv\xxxxxxx\camera_param.cpp 16

Error C2061 syntax error: identifier 'Params' ArduCam_test c:\users\clang\desktop\working folder\opencv\xxxxxxx\camera_param.h 11

Error C2653 'cv': is not a class or namespace name xxxxxx c:\users\clang\desktop\working folder\opencv\arducam_test\camera_param.h 11

If I condense this into just a function its no problem, but path of least resistance is not desired in thisw example...need class. What's wrong with my code?
Last edited on
When the compiler gets to your camera_param header, no code has declared what cv is so the compiler has no idea what cv is. That namespace doesn't exist as far as the compiler is concerned. You need cv to exist BEFORE the compiler gets to cv in your header file.
Taking your suggestion I took"camera_param.h" and move it under all of the system <>/opencv "" includes. Then it had all of the missing info to properly process the object being passed.

Thank you
Last edited on
That will fix it in this case.

Note that it's considered bad practice to have a header file that doesn't stand alone (i.e. if I want something from it, I should only have to #include that header); a header file that relies on other header files having already been #include d to work should #include the necessary header files itself.
Topic archived. No new replies allowed.