提升线程中的"too few arguments to function"
"too few arguments to function" in boost thread
我正在尝试开发一个立体视觉系统。每当我尝试构建代码时,我都会收到以下消息:
***** Build of configuration Debug for project RicoCameraCpp ****
make all
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -I/home/ux/Downloads -I/usr/local/boost_1_52_0/boost -I/usr/local/boost_1_52_0 - I/home/ux/Downloads/opencv2 -include/home/ux/Downloads/opencv2/opencv_modules.hpp -include/usr/local/boost_1_52_0/boost/thread.hpp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
In file included from /usr/local/boost_1_52_0/boost/thread/thread.hpp:22:0,
from /usr/local/boost_1_52_0/boost/thread.hpp:13,
from <command-line>:0:
/usr/local/boost_1_52_0/boost/thread/detail/thread.hpp: In member function ‘void boost::detail::thread_data<F>::run() [with F = int (*)(int, char**)]’:
../main.cpp:81:1: instantiated from here
/usr/local/boost_1_52_0/boost/thread/detail/thread.hpp:78:17: error: too few arguments to function
/usr/local/boost_1_52_0/boost/system/error_code.hpp: At global scope:
/usr/local/boost_1_52_0/boost/system/error_code.hpp:214:36: warning: ‘boost::system::posix_category’ defined but not used [-Wunused-variable]
/usr/local/boost_1_52_0/boost/system/error_code.hpp:215:36: warning: ‘boost::system::errno_ecat’ defined but not used [-Wunused-variable]
/usr/local/boost_1_52_0/boost/system/error_code.hpp:216:36: warning: ‘boost::system::native_ecat’ defined but not used [-Wunused-variable]
make: *** [main.o] Error 1
**** Build Finished *****
这是我的代码:
#include "cstdlib"
#include "cmath"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "boost/thread.hpp"
#include <iostream>
using namespace std;
using namespace boost;
using namespace cv;
int firstCam( int argc, char** argv )
{
//initilize first camera
CvCapture* captureRightCam = cvCaptureFromCAM(0);
//check if first camera is available
if(!captureRightCam)
{
cout << "No first camera to capturen";
return(-1);
}
//create right window
cvNamedWindow( "Right Cam", CV_WINDOW_AUTOSIZE );
//display frames for every cvWaitKey duration
while ( 1 )
{
//get frames
IplImage* rightFrame = cvQueryFrame( captureRightCam );
//check if captured
if ( !rightFrame )
{
fprintf( stderr, "ERROR: frame is null...n" );
getchar();
break;
}
//show frames inside the windows
cvShowImage( "Right Cam", rightFrame );
cvWaitKey(150);
}
//release and destroy windows
cvReleaseCapture( &captureRightCam );
cvDestroyWindow( "Right Cam" );
return 0;
}
int secondCam( int argc, char** argv )
{
CvCapture* captureLeftCam = cvCaptureFromCAM(1);
if(!captureLeftCam)
{
cout << "No second camera to capturen";
return(-1);
}
cvNamedWindow( "Left Cam", CV_WINDOW_AUTOSIZE );
while ( 1 )
{
IplImage* leftFrame = cvQueryFrame( captureLeftCam );
if ( !leftFrame )
{
fprintf( stderr, "ERROR: frame is null...n" );
getchar();
break;
}
cvShowImage( "Left Cam", leftFrame );
cvWaitKey(150);
}
cvReleaseCapture( &captureLeftCam );
cvDestroyWindow( "Left Cam" );
return 0;
}
int main()
{
boost::thread t1(firstCam);
boost::thread t2(secondCam);
return 0;
}
我做错了什么?
我认为错误消息是非常描述性的,实际上:
您正试图从函数firstCam
中生成一个线程。该函数接受两个参数,但当您创建线程时,不会给它任何参数。因此,它无法确定要传递给函数的参数,因此抱怨"参数太少"。
在这种情况下,您似乎从某个地方复制了函数签名,而没有考虑它。您根本不会使用argc
和argv
。
(附带说明:
using namespace std;
using namespace boost;
using namespace cv;
是个坏主意,迟早会给你带来麻烦。详见GotW 53。)
相关文章:
- 具有变量Number of Arguments的std::函数的矢量
- 如何修复"too few arguments to function"?
- 开放CV垫"Sizes of input arguments do not match"的问题
- 有没有办法在初始化字符串时避免来自 clang-tidy(fuchsia-default-arguments)的警告?
- glGenVertexArrays and glGenBuffers arguments
- 'type_alias<char[N]>{}' VS 'char[N]{}' in function's arguments
- Command Line Arguments wxCmdLineArgsArray in wxWidgets
- OpenCV std::vector for cv::Mat arguments
- map.insert:"Invalid arguments"错误与 pair<enum,vector<*>>
- VS说"Too few arguments...",但其他编译器给了我正确的输出?
- Win32 CreateThread() Arguments Zero'ed?
- Eclipse CDT - 使用模板默认值时的"Invalid arguments"
- "All arguments to functions are passed by value" C 中的,C++ 中对引用传递的混淆
- std::result_of for lvalue/rvalue arguments
- RPC:xdr_bytes "Can't encode arguments"当阵列太大时
- 是“ Gnu-Zero-variadic-Macro-arguments”可靠地忽略
- 如何修复("too few arguments in function call")?
- GNU argp "too few arguments"
- 提升线程中的"too few arguments to function"
- SQL Server 连接字符串"To few arguments"