g++ v14.1.0

Liste des GroupesRevenir à cl c++ 
Sujet : g++ v14.1.0
De : student (at) *nospam* invalid.invalid (Student Project)
Groupes : comp.lang.c++
Date : 17. Dec 2024, 05:39:58
Autres entêtes
Organisation : To protect and to server
Message-ID : <vjqvhu$305fb$1@paganini.bofh.team>
Do you guys see any problems in this simple code:

struct Timer
{
std::chrono::time_point<std::chrono::steady_clock> start, end;
std::chrono::duration<float> duration;

Timer()
{
start = std::chrono::high_resolution_clock::now();
}

~Timer()
{
end = std::chrono::high_resolution_clock::now();
duration = end - start;

float ms = duration.count() * 1000.0f;
std::cout << "Timer took: " << ms << "ms\n";
}
};

This code compiles with clang++ and even Visual Studio (Visual Studio
2022 Developer Command Prompt v17.12.3) but g++ gives many errors such
as this:

g++ -o Program2.exe -Wall main.cpp
main.cpp: In constructor 'Timer::Timer()':
main.cpp:16:65: error: no match for 'operator=' (operand types are
'std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >' and
'std::chrono::_V2::system_clock::time_point' {aka
'std::chrono::time_point<std::chrono::_V2::system_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >'})
    16 |                 start = std::chrono::high_resolution_clock::now();
       |                                                                 ^
In file included from C:/msys64/ucrt64/include/c++/14.1.0/chrono:41,
                  from main.cpp:2:
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:
candidate: 'constexpr
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> >
 >::operator=(const
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&)'
   922 |       class time_point
       |             ^~~~~~~~~~
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:   no
known conversion for argument 1 from
'std::chrono::_V2::system_clock::time_point' {aka
'std::chrono::time_point<std::chrono::_V2::system_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >'} to
'const std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&'
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:
candidate: 'constexpr
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> >
 >::operator=(std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&&)'
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:   no
known conversion for argument 1 from
'std::chrono::_V2::system_clock::time_point' {aka
'std::chrono::time_point<std::chrono::_V2::system_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >'} to
'std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&&'
main.cpp: In destructor 'Timer::~Timer()':
main.cpp:21:63: error: no match for 'operator=' (operand types are
'std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >' and
'std::chrono::_V2::system_clock::time_point' {aka
'std::chrono::time_point<std::chrono::_V2::system_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >'})
    21 |                 end = std::chrono::high_resolution_clock::now();
       |                                                               ^
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:
candidate: 'constexpr
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> >
 >::operator=(const
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&)'
   922 |       class time_point
       |             ^~~~~~~~~~
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:   no
known conversion for argument 1 from
'std::chrono::_V2::system_clock::time_point' {aka
'std::chrono::time_point<std::chrono::_V2::system_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >'} to
'const std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&'
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:
candidate: 'constexpr
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&
std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> >
 >::operator=(std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&&)'
C:/msys64/ucrt64/include/c++/14.1.0/bits/chrono.h:922:13: note:   no
known conversion for argument 1 from
'std::chrono::_V2::system_clock::time_point' {aka
'std::chrono::time_point<std::chrono::_V2::system_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >'} to
'std::chrono::time_point<std::chrono::_V2::steady_clock,
std::chrono::duration<long long int, std::ratio<1, 1000000000> > >&&'



Date Sujet#  Auteur
17 Dec 24 * g++ v14.1.04Student Project
17 Dec 24 `* Re: g++ v14.1.03Bonita Montero
17 Dec 24  `* Re: g++ v14.1.02Student Project
18 Dec 24   `- Re: g++ v14.1.01Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal