小编And*_*993的帖子

'memcpy'未在此范围内声明

我正在尝试用gcc和eclipse构建一个开源的c ++库.但我得到此错误'memcpy'未在此范围内声明

我试着包含memory.h(和string.h),如果我点击"打开声明",eclipse会找到该函数,但gcc会给我错误.

我能怎么做?

#include <algorithm>
#include <memory.h>

namespace rosic
{
   //etc etc
template <class T>
  void circularShift(T *buffer, int length, int numPositions)
  {
    int na = abs(numPositions);
    while( na > length )
      na -=length;
    T *tmp = new T[na];
    if( numPositions < 0 )
    {

      memcpy(  tmp,                buffer,              na*sizeof(T));
      memmove( buffer,            &buffer[na], (length-na)*sizeof(T));
      memcpy( &buffer[length-na],  tmp,                 na*sizeof(T));
    }
    else if( numPositions > 0 )
    {
      memcpy(  tmp,        &buffer[length-na],          na*sizeof(T));
      memmove(&buffer[na],  buffer,            (length-na)*sizeof(T));
      memcpy(  buffer,      tmp,                        na*sizeof(T));
    }
    delete[] tmp; …
Run Code Online (Sandbox Code Playgroud)

c++ gcc

21
推荐指数
1
解决办法
6万
查看次数

Qt安卓。获取设备屏幕分辨率

我正在 android 设备上使用 qt 5.3 进行开发。我无法获得屏幕分辨率。使用旧的 qt 5 版本,此代码有效:

QScreen *screen = QApplication::screens().at(0);
largh=screen->availableGeometry().width();
alt  =screen->availableGeometry().height();
Run Code Online (Sandbox Code Playgroud)

但是现在它不起作用(返回屏幕尺寸 00x00)。还有另一种方法吗?谢谢

qt android resolution screen pixel

5
推荐指数
1
解决办法
6277
查看次数

缩写类中定义的类型的全名

当我使用类中定义的类型时,哪种方法可以避免编写类名?

例如,我有一个类MyClass定义了一个mytype类型,我需要使用这个类mytype,我必须写:

MyClass::mytype foo
Run Code Online (Sandbox Code Playgroud)

我只想写

mytype foo
Run Code Online (Sandbox Code Playgroud)

我试过了

#define MyClass::mytype mytype
Run Code Online (Sandbox Code Playgroud)

它有效,但我认为这不是一个好的解决方案.我该怎么用?

c++

2
推荐指数
1
解决办法
408
查看次数

矢量不转换括号括号列表

Matrix用这种类型的构造函数创建了一个类:

Matrix<T>(const vector<vector<T>> &m)
Run Code Online (Sandbox Code Playgroud)

如果我这样做,我可以实例化一个Matrix对象:

vector<vector<double>> a_v {
        { 17,    24,    1},
        { 23,    5,     7 },
        {  4,     6,    13 }

    };

    Matrix<double> a=a_v;
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我认为che构造函数应该作为类型转换器,我认为这个代码也应该工作:

    Matrix<double> a= {
    { 17,    24,    1},
    { 23,    5,     7 },
    {  4,     6,    13 }

};
Run Code Online (Sandbox Code Playgroud)

但是使用第二个代码我收到此错误:

无法将"{{17,24,1},{23,5,7},{4,6,13}}"从"大括号括号初始化列表"转换为"矩阵"

为什么C++11不转换brace-enclosed initializervector<vector<double>>自动?

如果我想以这种方式初始化矩阵,我该怎么办?

c++11 list-initialization

2
推荐指数
1
解决办法
392
查看次数

为什么在调用模板化函数时不考虑参数转换?

我有一个模板类和一个朋友operator*函数

StereoSmp<TE> operator* (const StereoSmp<TE>& a, TE b)
Run Code Online (Sandbox Code Playgroud)

我使用它TE=float但我需要增加一个StereoSmp<float> * double 我认为应该是可能的因为它应该自动转换doublefloat有效但我得到错误:

no match for ‘operator*’ (operand types are ‘StereoSmp<float>’ and
    ‘__gnu_cxx::__alloc_traits<std::allocator<double> >::value_type {aka double}’) 
deduced conflicting types for parameter ‘TE’ (‘float’ and ‘double’)
Run Code Online (Sandbox Code Playgroud)

为什么它不会自动将double转换为float?我该怎么做才能允许类型之间的自动转换?

c++ templates

2
推荐指数
1
解决办法
84
查看次数

标签 统计

c++ ×3

android ×1

c++11 ×1

gcc ×1

list-initialization ×1

pixel ×1

qt ×1

resolution ×1

screen ×1

templates ×1