Cant use 'auto' in my class.

Hello, I want to create
 
auto lastDataSendTime = std::chrono::system_clock::now();

in my class, because I got error:
 
'auto' not allowed in non-static class member

How to use it in my class?
You have two options:
1. Compile using C++ 11
2. Use the time_point data type.

 
std::chrono::system_clock::time_point lastDataSendTime = std::chrono::system_clock::now()


Edit:
Woops...
See
https://stackoverflow.com/questions/11302981/c11-declaring-non-static-data-members-as-auto
Last edited on
Ok, this method what u posted working.

Now I have similar problem.

1
2
3
4
5
6
7
8
9
void Misc::sendData(std::map<std::string, std::string> data) {
...
}

void Misc::loop(){
...
std::thread t1(sendData, toSend); // Reference to non-static member function must be called
...
}
Google's guess:
std::thread t1( &Misc::sendData, toSend );
With this solution I got these errors:

1
2
3
static assertion failed: Wrong number of arguments for pointer-to-member
       static_assert(_Varargs::value
       ^


1
2
3
4
5
6
D:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\c++\functional:1505: error: no type
named 'type' in 'class std::result_of<std::_Mem_fn<void (Misc::*)
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>'
       typedef typename result_of<_Callable(_Args...)>::type result_type;
                                                             ^


1
2
3
4
5
6
D:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\c++\functional:1526: error: no type
named 'type' in 'class std::result_of<std::_Mem_fn<void (Misc::*)
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>'
         _M_invoke(_Index_tuple<_Indices...>)
         ^

Last edited on
If Misc::sendData is not a static member function you need to pass the Misc object as the second argument to the thread constructor.
Registered users can post here. Sign in or register to post.