当我编译traingl e_test.cpp程序时,当gtest.h头文件包含在文件中时,我会得到以下错误。
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest-message.h:55:0,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest-assertion-result.h:46,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest.h:59,
from traingle_test.cpp:2:
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1238:8: error: 'mutex' in namespace 'std' does not name a type
std::mutex mu_;
^~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1239:8: error: 'condition_variable' in namespace 'std' does not name a type
std::condition_variable cv_;
^~~~~~~~~~~~~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h: In member function 'void testing::internal::Notification::Notify()':
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:21: error: 'mutex' is not a member of 'std'
std::lock_guard<std::mutex> lock(mu_);
^~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:21: error: 'mutex' is not a member of 'std'
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:31: error: template argument 1 is invalid
std::lock_guard<std::mutex> lock(mu_);错误信息

traingle_test.cpp
#include "traingle.h"
#include <gtest/gtest.h>
namespace {
TEST (TraingleTest, InvalidSides){
EXPECT_EQ(-1, TypeOfTraingle(-10, 20, 30));
EXPECT_EQ(-1, TypeOfTraingle(10, -20, 30));
EXPECT_EQ(-1, TypeOfTraingle(3, 4, -8));
}
}traingle.cpp
#include "traingle.h"
/* Return values
1 for equilateral, 2 for isosceles, 3 for scalan
0 for traingle can't be formed with given sides
-1 if any side value is invalid, say -ve
*/
int TypeOfTraingle(int a, int b, int c){
if(a<0 || b<0 || c<0)
return -1;
if(!(a+b > c && b + c > a && a + c > b))
return 0;
else if (a==b && b==c)
return 2;
else
return 3;
}traingle.h
#ifndef __TRIANGLE_H
#define __TRIANGLE_H
int TypeOfTraingle(int, int, int);
#endif这里有3个文件-- traingle.cpp (计算在这里完成)、traingle_test.cpp (编写了测试用例)和traingle.h (包含函数声明)。测试用例文件需要与traingle.cpp链接,输出是通过多少个测试用例,以及基于测试用例值(x,y,z)的类型(等边、等腰和斜角三角形),如下图所示。

发布于 2022-10-26 19:09:44
https://stackoverflow.com/questions/74205631
复制相似问题