I have a function definition like this:
double getPriceTimeByPtr(const StrategyParams* ptr, const int applied_price, const int timeframe, const int shift, const int shift_delta, const bool normalized, time_t &time);
but when I compile this code it errors just before the &time part so clearly there is a problem passing a time_t object by reference.
How do I fix this please?
I recently added the time_t parameter to the function and the error occurred since then.
Here's the errors generated:
Severity Code Description Project File Line Suppression
State
Error C2143 syntax error: missing ')' before '&'
Error C2143 syntax error: missing '{' before '&'
Error C2059 syntax error: '&'
Error C2059 syntax error: ')'
The syntax seems correct to me but the compiler doesn't like it.
The project that was failing was defined as a C project which was then trying to call a C++ function by reference. C can't us by reference so was failing. Changing the time parameters to pointers worked.
I have an c++ example project from an USB 3.0 Interface vendor called streamer application from cypress fx3. I wanted to get this to run first and see the potential behind the application but unfornately I'm getting a whole set of errors when building in Visual Studio 2017.
I get errors in the main file streamer.cpp showing me the errors:
Error (active) E0079 expected a type specifier Line 26
Error (active) E1986 an ordinary pointer to a C++/CLI ref class or interface >class is not allowed Line 28
in Code:
#include "stdafx.h"
#include <windows.h>
// windows.h includes WINGDI.h which
// defines GetObject as GetObjectA, breaking
// System::Resources::ResourceManager::GetObject.
// So, we undef here.
#undef GetObject
#include "Streamer.h"
#undef MessageBox
using namespace System::Windows::Forms;
using namespace Streams;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
try
{
Application::Run(new Form1()); // THIS IS LINE 26
}
catch (Exception *e) // THIS IS LINE 28
{
MessageBox::Show(e->StackTrace,e->Message);
}
return 0;
}
Form 1 is part of streamer.h . In streamer h the error amount exceedes 400.
Most often compiler tells me identifier expected (E0040) even for syntax like private and public. Then the "this" operator causes an error:
Error (active) E0258 'this' may only be used inside a nonstatic member >function
What I tried to get this running:
- Installing missing windows sdk version 8.1 via installation routine in windows system control
- Changing Common Language Runtime Support to /clr
- inluding all missing header-files, compiler is now finding these header files.
Seems to me that there is something missing in the source project. Can you push me in the right direction?
catch (Exception *e)
That is an unmanaged exception. You need to catch a managed exception:
catch (Exception^ e)
I picked (ie copy-pasted) the following example from Boost documentation (http://www.boost.org/doc/libs/1_55_0b1/libs/assign/doc/index.html#operator+=):
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/assert.hpp>
using namespace std;
using namespace boost::assign; // bring 'operator+=()' into scope
{
vector<int> values;
values += 1,2,3,4,5,6,7,8,9; // insert values at the end of the container
BOOST_ASSERT( values.size() == 9 );
BOOST_ASSERT( values[0] == 1 );
BOOST_ASSERT( values[8] == 9 );
}
Which throws the following error:
$ g++ boost_assign.cpp
boost_assign.cpp:6:1: error: expected unqualified-id before ‘{’ token
{
^
What's wrong ? Are the boost examples not directly copy-paste-run-able ?
Those examples are not copy-paste-run-able. Code enclosed in braces needs to be pasted somewhere in a function.
I've been working on a C++ project using Boost, and between compiles, I must have upgraded something in boost without meaning to or something, because now Boost dependencies won't compile:
In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah.h:4,
from bluh.h:3,
from bleh/main.cpp:4:
/usr/include/boost/thread/xtime.hpp:23:5: error: expected identifier before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected '}' before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected unqualified-id before numeric constant
/usr/include/boost/thread/xtime.hpp:46:14: error: expected type-specifier before 'system_time'
In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah,
from /bleh,(changed these names, obviously)
from /bluh /main.cpp:4:
/usr/include/boost/thread/xtime.hpp: In function 'int xtime_get(xtime*, int)':
/usr/include/boost/thread/xtime.hpp:73:40: error: 'get_system_time' was not declared in this scope
/usr/include/boost/thread/xtime.hpp:73:40: note: suggested alternative:
/usr/include/boost/thread/thread_time.hpp:19:24: note: 'boost::get_system_time'
/usr/include/boost/thread/xtime.hpp: At global scope:
/usr/include/boost/thread/xtime.hpp:88:1: error: expected declaration before '}' token
make[2]: *** [CMakeFiles/edge_based_tracker.dir/main.o] Error 1
make[1]: *** [CMakeFiles/edge_based_tracker.dir/all] Error 2
make: *** [all] Error 2
Any ideas? I tried changing TIME_UTC to TIME_UTC_ as this was recommended to me on another site, but that didn't seem to help.
EDIT: The Boost Version is Version: 1.48.0.2. I've attached xtime below:
// Copyright (C) 2001-2003
// William E. Kempf
// Copyright (C) 2007-8 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_XTIME_WEK070601_HPP
#define BOOST_XTIME_WEK070601_HPP
#include <boost/thread/detail/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
enum xtime_clock_types
{
TIME_UTC=1 //LINE 23
// TIME_TAI,
// TIME_MONOTONIC,
// TIME_PROCESS,
// TIME_THREAD,
// TIME_LOCAL,
// TIME_SYNC,
// TIME_RESOLUTION
};
struct xtime
{
#if defined(BOOST_NO_INT64_T)
typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
#else
typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
#endif
typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
xtime_sec_t sec;
xtime_nsec_t nsec;
operator system_time() const
{
return boost::posix_time::from_time_t(0)+
boost::posix_time::seconds(static_cast<long>(sec))+
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
boost::posix_time::nanoseconds(nsec);
#else
boost::posix_time::microseconds((nsec+500)/1000);
#endif
}
};
inline xtime get_xtime(boost::system_time const& abs_time)
{
xtime res;
boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
return res;
}
inline int xtime_get(struct xtime* xtp, int clock_type)
{
if (clock_type == TIME_UTC)
{
*xtp=get_xtime(get_system_time());
return clock_type;
}
return 0;
}
inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
{
if (xt1.sec == xt2.sec)
return (int)(xt1.nsec - xt2.nsec);
else
return (xt1.sec > xt2.sec) ? 1 : -1;
}
} // namespace boost
#include <boost/config/abi_suffix.hpp>
#endif //BOOST_XTIME_WEK070601_HPP
EDIT: To make it clear, the code is failing on an import of boost/thread.hpp
For those running into the same issue and struggling to find the solution here.
Derived from noodlebox' link (https://svn.boost.org/trac/boost/ticket/6940):
You can edit /usr/include/boost/thread/xtime.hpp (or whereever your xtime.hpp lies)
and change all occurrences of TIME_UTC to TIME_UTC_ - Probably around lines 23 and 71.
i.e. sed -i 's/TIME_UTC/TIME_UTC_/g' /usr/include/boost/thread/xtime.hpp
If you're getting syntax errors when using Boost, you may need to compile your code with -std=c++11.
The TIME_UTC issue you might have read about is a side effect of using c++11. TIME_UTC is now defined as a macro in c++11, so you will need to either replace all instances of TIME_UTC with TIME_UTC_, or just use a newer (1.50.0+) version of Boost where this has been fixed already.
See: https://svn.boost.org/trac/boost/ticket/6940
Since you do not show your code, we can only guess. My guess is that you define TIME_UTC macro somewhere in your code. This macro messes-up xtime.hpp header.
#include <windows.h>
int main()
{
CreateSymbolicLink(L"d:\\symbolic_link_to_notepad.exe",
L"c:\\windows\\notepad.exe", 0); // Success!
}
However, when I double-click d:\symbolic_link_to_notepad.exe to start notepad, an error message box pops and says the path is not found.
What's the root cause?