I'm trying to set the session settings but I'm getting an error I don't quite understand, I am able to get the session settings OK and according to the Libtorrent docs I simply pass the session_settings structure to set_settings once I have changed any values.
using namespace libtorrent;
session* Session;
session_status* Session_Status;
session_settings* Session_Settings;
bool Start_Client_Sess()
{
Session = new session;
Session_Status = new session_status;
Session_Settings = new session_settings;
Session->settings( );
std::cout << "upload_rate_limit " << Session_Settings->upload_rate_limit << " \n";
std::cout << "dht_announce_interval " << Session_Settings->dht_announce_interval << " \n";
Session_Settings->upload_rate_limit = 200;
Session_Settings->dht_announce_interval = 1800;
Session->set_settings( Session_Settings ); // error
}
Error:
1>Source\Client_F.cpp(66): error C2664: 'void libtorrent::session::set_settings(const libtorrent::session_settings &)' : cannot convert argument 1 from 'libtorrent::session_settings *' to 'const libtorrent::session_settings &'
1> Reason: cannot convert from 'libtorrent::session_settings *' to 'const libtorrent::session_settings'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
As the error message says, you don't have to pass a pointer to this function.
Session->set_settings( *Session_Settings );
Related
I have a Visual C++ 6.0 project which I need to update and I import it to Visual Studio 2012 with no problems, however, during compilation, I get the following four errors:
Error 1 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CTrendDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\trenddlg.cpp 89
Error 6 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CManualDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\manualdlg.cpp 175
Error 7 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CManualDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\manualdlg.cpp 177
Error 8 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CManualDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\manualdlg.cpp 178
The first error is originating from the following line of code, and the rest are similar:
ON_COMMAND_RANGE(IDC_CHECK_PEN, IDC_CHECK_GRID, OnCheckButtons)
ON_COMMAND_RANGE(IDC_REF_L1, IDC_REF_L16, OnCarriagePos)
ON_COMMAND_RANGE(IDC_VALVE_L1, IDC_VALVE_L4, OnValve)
ON_COMMAND_RANGE(IDC_SAMPLE_L_A, IDC_SAMPLE_L_B, OnDetector)
Where (as an instance) OnCheckButtons function is defined in TrendDlg.cpp as follows:
void CTrendDlg::OnCheckButtons(int id)
{
UINT state;
RECT rect = {m_rect.left-60, m_rect.top-10, m_rect.right+40, m_rect.bottom+30};
state = ((CButton*)GetDlgItem(id))->GetState();
if ((state & 0x0003) == 1)
{
switch (id)
{
case IDC_CHECK_PEN:
m_pen = TRUE;
break;
case IDC_CHECK_LINE:
m_line = TRUE;
break;
case IDC_CHECK_BUBBLES:
m_bubble = TRUE;
break;
case IDC_CHECK_GRID:
m_grid = TRUE;
}
}
else
{
switch (id)
{
case IDC_CHECK_PEN:
m_pen = FALSE;
break;
case IDC_CHECK_LINE:
m_line = FALSE;
break;
case IDC_CHECK_BUBBLES:
m_bubble = FALSE;
break;
case IDC_CHECK_GRID:
m_grid = FALSE;
}
}
InvalidateRect(&rect);
}
my message map range is also defined as:
BEGIN_MESSAGE_MAP(CTrendDlg, CDialog)
Why is the compiler trying to cast CTrendDlg and CManualDlg type to CCmdTarget type? is there a change in class structure from VC 6.00 to VS2012?
I appreciate your help.
Your handler should be defined like this:
void CTrendDlg::OnCheckButtons(UINT id)
So basically change int to UINT
See here how this macro ON_COMMAND_RANGE should be used:
1) You need a proper signature, return void and the parameter should be of type UINT
2) Qualify your method with class name:
ON_COMMAND_RANGE(IDC_CHECK_PEN, IDC_CHECK_GRID, &CTrendDlg::OnCheckButtons)
^^^^^^^^^^^^
VS 6.0 is quite old, modern VS versions are more standard conformant.
Basically I have the next function that I need to call Async:
void waitForFrames(){
CMFTWrapper::IsRunning = true;
while (CMFTWrapper::IsRunning){
result = WaitForSingleObjectEx(CMFTWrapper::FrameEvent, INFINITE, true);
if (result != WAIT_OBJECT_0){
// capture aborted, quit.
}
else if (CMFTWrapper::count > 0){
// copy the bitmap data
}
}
}
Now I tried doing it like this:
create_task(waitForFrames())
.then([this](task<void> frameTask)
{
XTRACE(L"=================================FINISHED WITH FRAME TASK\n");
});
This gives me the next error:
Error 26 error C2228: left of '.then' must have class/struct/union C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager\WinRT\DeviceDetection\LmiVideoCapturerWinRTImplementation.cpp 181 1 Vidyo.DeviceManager
Error 24 error C2784: 'Concurrency::task<_Ty> Concurrency::create_task(const Concurrency::task<_Ty> &)' : could not deduce template argument for 'const Concurrency::task<_Ty> &' from 'void' C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager\WinRT\DeviceDetection\LmiVideoCapturerWinRTImplementation.cpp 180 1 Vidyo.DeviceManager
Error 25 error C2784: 'Concurrency::task<details::_TaskTypeFromParam<_Ty>::_Type> Concurrency::create_task(_Ty,Concurrency::task_options)' : could not deduce template argument for '_Ty' from 'void' C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager\WinRT\DeviceDetection\LmiVideoCapturerWinRTImplementation.cpp 180 1 Vidyo.DeviceManager
Error 45 error LNK1104: cannot open file 'C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Build\ARM\Release\Vidyo.DeviceManager\LmiDeviceManagerWinRT.lib' C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager.Test\LINK Vidyo.DeviceManager.Test
Now I tried changing the return value of the function to other stuff from void (Dword, int) but still I get a similar error.
Watching over examples I found on the net, all the functions that use this, that I found return back IAsyncAction.
Example:
create_task(m_pMediaCapture->StartRecordToStorageFileAsync(m_EncodingProfile, m_recordStorageFile))
.then([this](task<void> recordTask)
{
XTRACE(L"=================================will try to get record task\n");
}
How can I do this with my normal function, so that it can run async?
You can pass a lambda directly to the create_task function:
create_task( [](){ /* code here */ } ).
So in your scenario the following should work:
create_task([](){ waitForFrames(); })
.then([this](task<void> frameTask){
XTRACE(L"=================================FINISHED WITH FRAME TASK\n");
});
In the following protocol buffer, how does one access the repeated fields in the extension from C++?
base.proto
message Base {
optional int32 id = 1;
repeated int32 ids = 2;
optional string name = 3;
repeated string names = 4;
extensions 1000 to 1999;
}
ext.proto
import "base.proto";
extend Base {
repeated string names = 1000;
optional int32 number = 1001;
repeated int32 numbers = 1002;
optional string name = 1003;
}
The following doesn't compile (in VS2010)
#include "base.pb.h"
#include "ext.pb.h"
using namespace ::google::protobuf;
int main(int argc, char *argv[])
{
Base b;
RepeatedPtrField<std::string> base_names = b.names(); // OK
RepeatedField<int> base_ids = b.ids(); // OK
int ext_number = b.GetExtension(number); // OK
std::string ext_name = b.GetExtension(name); // OK
assert( b.HasExtension(numbers) ); // OK
assert( b.HasExtension(names) ); // OK
int32 i = b.GetExtension(numbers); // ? Compiles but doesn't make sense.
RepeatedField<int32> ext_numbers = b.GetExtension(numbers); // compilation fails:
RepeatedPtrField<std::string> ext_names = b.GetExtension(names); // compilation fails:
return 0;
}
Compilation errors
1>test_proto.cpp(17): error C2440: 'initializing' : cannot convert from 'int' to 'google::protobuf::RepeatedField<Element>'
1> with
1> [
1> Element=google::protobuf::int32
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>\test_proto.cpp(18): error C2440: 'initializing' : cannot convert from 'const std::string' to 'google::protobuf::RepeatedPtrField<Element>'
1> with
1> [
1> Element=std::string
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
Thanks to Feng Xiao on the protobuf mailing list, use ExtensionSize(id) and GetExtension(id, index):
Base b;
int index = 0;
if (index < b.ExtensionSize(names))
{
std::string s_value = b.GetExtension(names, index);
}
I am using the MArgList class from the Maya API to retrieve arguments entered in the Maya command line. According to the class reference MArgList::get should be able to take an int or double as its second argument but it seems to be expecting a bool only and so throws a conversion error during compiling. The following is the code section and the errors generated. Any thoughts on what might be causing this would be much appreciated. The code was typed straight out of a tutorial on Maya plugin development, so it is a mystery why it is not working.
const int nPosts = 5;
const double radius = 0.5;
const double height = 5.0;
unsigned index;
index = args.flagIndex( "n", "number" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, nPosts );
unsigned index;
index = args.flagIndex( "r", "radius" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, radius );
unsigned index;
index = args.flagIndex( "h", "height" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, height );
1>Posts1Cmd.cpp(37): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const int' to 'bool &'
1>Posts1Cmd.cpp(39): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(42): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
1>Posts1Cmd.cpp(44): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(47): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If you are going to get new values from the get function, you cannot have the target variables const.
Try
int nPosts = 5;
double radius = 0.5;
double height = 5.0;
Also, you should not declare a new index variable for each call. Just declare it once and reuse it.
I'm making a function to take in a reference to a path on the filesystem and recursively add file names to a vector. But first I have to be able to add paths to a vector.
what is wrong with this method?
namespace filesys = boost::filesystem;
Method:
void recursive_file_list(filesys::path & root_path, vector<filesys::path> & paths) {
paths->push_back(*root_path); // line 14
// TODO: add more logic to actually recurse through file system
// for now just add root_path (even though root_path is path of directory, not file)
}
And I call it like so:
int main(int argc, char* argv[]) {
// Use the command line arguments
filesys::path abs_path; // line 23
if ( argc > 1 )
// Make the system complete this path to absolute path
abs_path = filesys::system_complete( filesys::path( argv[1] ) );
else {
// If no arguments given
cout << "usage: list_files [path]" << endl;
exit(1);
}
// Is this a valid path?
if (!filesys::exists( abs_path )) {
cout << "The path you have specified does not exist." << endl;
exit(2);
}
// If this is a directory
vector<filesys::path> filepaths();
if (filesys::is_directory( abs_path )) {
cout << "You have specified a directory." << endl;
recursive_file_list(&abs_path, &filepaths);
}
else {
cout << "You have specified a file." << endl;
}
}
Error:
list_files.cpp: In function 'void recursive_file_list(boost::filesystem3::path&, std::vector<boost::filesystem3::path, std::allocator<boost::filesystem3::path> >&)':
list_files.cpp:14: error: base operand of '->' has non-pointer type 'std::vector<boost::filesystem3::path, std::allocator<boost::filesystem3::path> >'
list_files.cpp:14: error: no match for 'operator*' in '*root_path'
list_files.cpp: In function 'int main(int, char**)':
list_files.cpp:43: error: invalid initialization of non-const reference of type 'boost::filesystem3::path&' from a temporary of type 'boost::filesystem3::path*'
list_files.cpp:13: error: in passing argument 1 of 'void recursive_file_list(boost::filesystem3::path&, std::vector<boost::filesystem3::path, std::allocator<boost::filesystem3::path> >&)'
I don't understand - I'm passing it by reference and then dereferencing it to add it...not sure what I'm doing wrong.
You can't dereference references! The * and -> operators do not apply to references; you would push the path itself to the vector itself:
paths.push_back(root_path); // line 14
and furthermore, you don't pass addresses to reference arguments, just the arguments themselves, so you would call the function like this:
recursive_file_list(abs_path, filepaths);
References have pointer-like non-copy semantics all by themselves; you do not need to help them along by taking addresses or trying to dereference them.