小编Jam*_*mal的帖子

是否可以使用CSS掩盖或剪裁图像的形状?

我想在CSS中创建这个设计.可能吗?

设计是这样的:

这是我的代码:

.triangle{
    border-radius: 50%;
    width: 120px;
    height: 120px;
}
.triangle img {
    width: 120px;
    height: 120px;
}
.triangle::after{
    right: 150px;
    top: 50%;
    border: solid transparent;
    content:"";
    height:  0px;
    width:  0px;
    position: absolute;
    pointer-events: none;
    border-color: white;
    border-left-color: white;/*white is the color of the body*/
    border-width: 60px;
    margin-top: -60px
}
Run Code Online (Sandbox Code Playgroud)
<div class="triangle">
    <img src="http://deskode.com/images/placeholder/team/07.jpg">
</div>
Run Code Online (Sandbox Code Playgroud)

形成三角形,但不是与图像相同.

的jsfiddle

html css css3 css-shapes

23
推荐指数
5
解决办法
2272
查看次数

在constexpr函数内变换int

我为什么这样做:

constexpr auto i_can() {
   int a = 8;
   a = 9;
   //...
}
Run Code Online (Sandbox Code Playgroud)

但我不能这样做:

constexpr auto i_cannot() {
    std::array<int, 10> arr{};
    //I cannot
    arr[5] = 9;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 如果我可以改变一个int,为什么我不能改变int数组内部的那个?
  2. 这是语言限制(C++ 14)还是标准库规范问题?reference std::array<T, N>::operator[](size_t)目前不是constexpr.

c++ constexpr c++14

23
推荐指数
2
解决办法
970
查看次数

使用STL排序功能对列表进行排序

我正在尝试按降序排序列表(类的一部分)包含a的项目struct,但它不编译:

错误:'__last - __first'中'operator-'不匹配

sort(Result.poly.begin(), Result.poly.end(), SortDescending());
Run Code Online (Sandbox Code Playgroud)

这是SortDescending:

struct SortDescending
{
    bool operator()(const term& t1, const term& t2)
    { 
        return t2.pow < t1.pow; 
    }
};
Run Code Online (Sandbox Code Playgroud)

谁能告诉我什么是错的?

c++ sorting stl list

22
推荐指数
2
解决办法
2万
查看次数

我应该如何大括号初始化std :: pairs的std :: array?

std::array<std::pair<int, int>, 2> ids = { { 0, 1 }, { 1, 2 } };
Run Code Online (Sandbox Code Playgroud)

VS2013错误:

错误C2440:'初始化':无法从'int'转换为'std :: pair'没有构造函数可以采用源类型,或构造函数重载解析是不明确的

我究竟做错了什么?

c++ c++11 std-pair list-initialization stdarray

22
推荐指数
2
解决办法
8174
查看次数

C++中的宏和const有什么区别?

我在技术访谈中被问到这个问题:

constC++中的a 和宏有什么区别?

我的回答是宏是一个预处理器指令,如果使用宏,可能很难调试应用程序,因为它在编译之前被常量表达式替换,而a const可以有类型标识符并且易于调试.

任何人都可以指出任何其他差异,哪些应该是首选?

编辑:

来自IBM C++文档:

以下是一些区别#defineconst类型修饰符:

  1. #define指令可用于为数字,字符或字符串常量创建名称,而可声明任何类型的const对象.

  2. const对象受变量的作用域规则约束,而使用的常量不受约束#define.与const对象不同,宏的值不会出现在编译器使用的中间源代码中,因为它们是内联扩展的.内联扩展使得调试器无法使用宏值.

  3. 宏可以用在常量表达式中,例如数组绑定,而const对象则不能.(我认为我们肯定需要使用宏来定义array_size.

  4. 编译器不会对宏进行类型检查,包括宏参数.

c++ macros const

20
推荐指数
2
解决办法
2万
查看次数

'脏旗'/'脏值'是什么意思?

我在工作中的一些源代码和其他一些代码中看到了一些名为'dirty'的变量.这是什么意思?什么是脏旗?

caching computer-architecture dirty-data

19
推荐指数
4
解决办法
2万
查看次数

为什么std :: accumulate函数显示向量<double>的错误总和?

考虑以下代码来添加a的所有元素vector:

#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
int main(void)
{

   std::vector<double> V;
   V.push_back(1.2);
   V.push_back(3.6);
   V.push_back(5.6);
   double sum = accumulate(V.begin(),V.end(),0);

   cout << "The sum of the elements of the vector V is " << sum << endl;
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我在Windows上的Cygwin上编译它并运行它时,我得到终端的输出为

矢量V的元素之和为9

accumulate功能似乎是将所有数字四舍五入并加起来,这可以解释答案.

这是什么问题Cygwin的G ++编译器,或我的误解accumulate添加了功能vectordoubleS'

c++ vector accumulate

19
推荐指数
3
解决办法
4241
查看次数

使用ios :: binary或ios :: out或两者打开文件有什么区别?

我试图找出打开文件之间的区别,如:

fstream *fileName*("FILE.dat",ios::binary);
Run Code Online (Sandbox Code Playgroud)

要么

fstream *fileName*("FILE.dat",ios::out);
Run Code Online (Sandbox Code Playgroud)

要么

fstream *fileName*("FILE.dat",ios::binary | ios::out);
Run Code Online (Sandbox Code Playgroud)

我发现,所有这些形式是相同的:在所有情况下,即使用产生该文件上的相同的输出*fileName*<<*fileName*.write().

c++ fstream

18
推荐指数
2
解决办法
2万
查看次数

使用CL/cl.h文件编译OpenCL程序

我有样品"Hello,World!" 来自网络的代码,我想在我大学的服务器上的GPU上运行它.当我输入"gcc main.c"时,它会响应:

CL/cl.h:没有这样的文件或目录

我该怎么办?我怎么能有这个头文件?

gpu opencl gpu-programming

18
推荐指数
2
解决办法
3万
查看次数

为无穷大建模最大双值

问题是关于在C++中为double数据类型建模无穷大.我需要在头文件中,所以我们不能使用像numeric_limits.

是否有定义的常量代表最大值?

c++ double infinity

16
推荐指数
3
解决办法
4万
查看次数