Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a class that uses a timer.
The problem is that I cacnot assign "auto" to start/stop so I need the return data type to assign it to start and stop.

Is there a way to use auto using static or similar that allows #include <chrono> in the .cpp part only?

What I have tried:

class c_clase
{
public:
	void timer(char *title=0,int data_size=1){    	stop_time= chrono::system_clock::now();double us=(double) chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();	if (title) printf("%s time = %7lgms = %7lg MOPs\n",title,(double) us*1e-3, (double)data_size/us); start_time= chrono::system_clock::now(); }
private:
	std::chrono::time_point<std::chrono::system_clock> start_time,stop_time;
};
Posted
Updated 9-Oct-17 20:38pm
v6

The type is std::chrono::system_clock::time_point.
 
Share this answer
 
Comments
Javier Luis Lopez 9-Oct-17 5:58am    
Thank you, I updated it but using
std::chrono::time_point<std::chrono::system_clock> if not errors appeared
Jochen Arndt 9-Oct-17 6:27am    
I have tested it meanwhile with the
std::chrono::time_point<std::chrono::system_clock> 
type and it works here (like also mentioned by CPallini).

" Is there a way to use auto using static or similar that allows #include <chrono> in the .cpp part only?"

No. Auto requires an initializer. While it is possible to have a static auto class member variable the requirement of the initializer implies that the variable must be const.
Quote:
Also tried:
std::chrono::time_point<std::chrono::system_clock> start_time,stop_time;
But link errors appeared

What errors did you get? I tried it. It compiles fine (once null_char was removed from the code).
 
Share this answer
 
Comments
Javier Luis Lopez 9-Oct-17 6:26am    
It was due #include <chrono> was not added to the .hpp code because I try write includes in the .cpp only or in a more complex project as in the following way:
https://photos.google.com/photo/AF1QipOtS9iHdhEHSJPpKOKrvy6X6ukVN2rETHklez1b

Thanks, at least I removed null_char; at the code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900