小编yay*_*yuj的帖子

有一个通过Laravel Eloquent

我有三个表garages,cars,securities.

证券是保证一辆车安全的证券,你可以拥有多个证券,但一个证券只能保证一辆汽车的安全.车库是汽车的所在地,也是证券.

我想要的是列出所有的证券并知道他所在车库的名称.问题是securities没有包含车库id的列,只有他保持安全的汽车的id,但汽车有车库的id.

Laravel雄辩有一个名为方法hasManyThrough,但securities有一个garage通过cars唯一的.

这是表格:

车库表:

-----------------------------------
|garage_id|garage_name|garage_size|
-----------------------------------
|        1|   Garage 1|        200|
-----------------------------------
|        2|   Garage 2|        400|
-----------------------------------
Run Code Online (Sandbox Code Playgroud)

汽车表:

---------------------------
|car_id|car_name|garage_id|
---------------------------
|     1|   Car 1|        1|
---------------------------
|     2|   Car 2|        1|
---------------------------
|     3|   Car 3|        2|
---------------------------
Run Code Online (Sandbox Code Playgroud)

证券表:

----------------------------------
|security_id|security_name|car_id|
----------------------------------
|          1|  Security 1|      1|
----------------------------------
|          2|  Security 2|      1|
----------------------------------
|          3|  Security 3|      2| …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent laravel-4 laravel-5

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

错误:将'const ...'传递为'...'的'this'参数会丢弃限定符

错误:将'const A'作为'void A :: hi()'的'this'参数传递,丢弃限定符[-fpermissive]

我不明白为什么我得到这个错误,我没有返回任何东西只是传递对象的引用,就是这样.

#include <iostream>

class A
{
public:
    void hi()
    {
        std::cout << "hi." << std::endl;
    }
};

class B
{
public:
    void receive(const A& a) {
        a.hi();
    }
};

class C
{
public:
    void receive(const A& a) {
        B b;
        b.receive(a);
    }
};

int main(int argc, char ** argv)
{
    A a;
    C c;
    c.receive(a);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

@编辑

我使用const正确性修复它但现在我试图在同一个方法中调用方法并得到相同的错误,但奇怪的是我没有传递对此方法的引用.

#include <iostream>

class A
{
public:
    void sayhi() const
    {
        hello();
        world();
    }

    void hello() …
Run Code Online (Sandbox Code Playgroud)

c++

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

从音频中绘制波形的算法

我正在尝试从原始音频文件中绘制波形.我使用FFmpeg对音频文件进行了解复用/解码,我有以下信息:样本缓冲区,样本缓冲区的大小,音频文件的持续时间(以秒为单位),采样率(44100,48000等),样本大小,样本format(uint8,int16,int32,float,double)和原始音频数据本身.

在互联网上挖掘我发现了这个算法(更多这里):

白噪声:

白噪声

算法

您需要做的就是将每个样本从-amplitude随机化为幅度.在大多数情况下,我们不关心通道的数量,因此我们只使用新的随机数填充每个样本.

Random rnd = new Random();
short randomValue = 0;

for (int i = 0; i < numSamples; i++)
{
    randomValue = Convert.ToInt16(rnd.Next(-amplitude, amplitude));
    data.shortArray[i] = randomValue;
}
Run Code Online (Sandbox Code Playgroud)

这真的很好,但我不想这样画,但这样:

大胆

是否有任何算法或想法如何使用我所拥有的信息绘制?

c++ algorithm audio ffmpeg

8
推荐指数
3
解决办法
1万
查看次数

OpenGL 纹理弯曲

我正在尝试在 OpenGL 中上传纹理,但纹理是弯曲的。

#include <iostream>

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <SOIL/SOIL.h>

#define GLSL(version, shader) "#version " #version "\n" #shader

const char * vertShader = GLSL(430,

    in vec2 position;
    in vec2 texcoord;

    out vec2 coordinates;

    void main() {
        coordinates = texcoord;
        gl_Position = vec4(position, 0.0, 1.0);
    }

);

const char * fragShader = GLSL(430,

    in vec2 coordinates;

    out vec4 color;

    uniform sampler2D texture;

    void main() {
        color = texture(texture, coordinates);
    }

);

int main(int argc, char ** argv)
{ …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glsl

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

avformat_open_input函数崩溃

我正在尝试使用avformat_open_input它来打开文件,即使该文件存在它也会崩溃.

av_register_all();

AVFormatContext *avFormatContext;

if (avformat_open_input(&avFormatContext, argv[1], NULL, NULL) < 0)
{
    av_log(0, AV_LOG_FATAL, "Wasn't possible opening the file: %s", argv[1]);
    return -1;
}
Run Code Online (Sandbox Code Playgroud)

c c++ ffmpeg

4
推荐指数
1
解决办法
1427
查看次数

覆盖注册关键字

考虑到这register是一个关键字,我们可以用它来命名函数/方法(我真的很想念它),我们不能这样做.但我想知道,覆盖该关键字是否危险?

#define register ...
Run Code Online (Sandbox Code Playgroud)

会有任何副作用吗?

c c++

3
推荐指数
1
解决办法
121
查看次数

错误:将'const ...'传递为'...'的'this'参数会丢弃调用方法中的限定符

我将一个对象的引用传递给一个函数,我使用const来表示它是只读方法,但如果我在该方法中调用另一个方法,则会发生此错误,即使我没有将引用作为参数传递.

错误:将'const A'作为'void A :: hello()'的'this'参数传递,丢弃限定符[-fpermissive]

错误:将'const A'作为'void A :: world()'的'this'参数传递,丢弃限定符[-fpermissive]

#include <iostream>

class A
{
public:
    void sayhi() const
    {
        hello();
        world();
    }

    void hello()
    {
        std::cout << "world" << std::endl;
    }

    void world()
    {
        std::cout << "world" << std::endl;
    }
};

class B
{
public:
    void receive(const A& a) {
        a.sayhi();
    }
};

class C
{
public:
    void receive(const A& a) {
        B b;
        b.receive(a);
    }
};

int main(int argc, char ** argv)
{
    A a;
    C c; …
Run Code Online (Sandbox Code Playgroud)

c++ member-functions

3
推荐指数
1
解决办法
1364
查看次数

void方法中的const-correctness和lambda'技巧'

我有一个方法接受一个对象的引用作为const,这个方法不会改变方法的任何内容,而const表明,这个方法也调用了类中的其他方法,并且是无效的不接受任何参数,也是虚拟的,这意味着扩展基类的类可以覆盖方法,但它也需要是const.例如:

#include <iostream>

class Boz
{
public:
    virtual void introduce() const = 0;
};

class Foo
{
public:
    virtual void callable() const
    {
        // ...
    }

    void caller(const Boz& object) const
    {
        callable();
        object.introduce();
    }
};

class Bar : public Boz
{
public:
    void introduce() const
    {
        std::cout << "Hi." << std::endl;
    }
};

class Biz : public Foo
{
public:
    void callable() const
    {
        std::cout << "I'm being called before the introduce." << std::endl;
    }
};

int main(void)
{ …
Run Code Online (Sandbox Code Playgroud)

c++ theory lambda c++11 c++14

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

超越boost的最佳选择:scoped_ptr <T> pimpl

我不使用升压只是标准的图书馆,我在一些问题眼看之间的主要区别boost::scoped_ptr<T>,并std::unique_ptr是,boost::scoped_ptr<T>既不是可复制也不是可移动的,那么我想知道,什么是最好的选择了boost::scoped_ptr<T>?使用std::unique_ptr或使用规则为三/五的原始指针以避免复制和移动?

c++ boost c++11 c++14

0
推荐指数
1
解决办法
127
查看次数