小编eli*_*264的帖子

使用原型的JavaScript中的类

我有一个问题,我想创建一个JavaScript类:

function Calculatore(txt,elements) {
    this.p= new Processor();
    this.output=txt;
    $(elements).click(this.clickHandler);   

}
Calculatore.prototype.clickHandler = function() {
var element=$(this);

// Code Here

// "this" contains the element.
// But what if I want to get the "output" var?
// I tried with Calculatore.prototype.output but no luck.

}
Run Code Online (Sandbox Code Playgroud)

那我怎么解决这个问题呢?

javascript jquery

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

如何在c ++中创建代码emmiter

我正在尝试用c ++创建一个代码emmiter,以便学习如何创建一个模拟器,但是我很难让动态汇编程序工作:

unsigned char program[] = {0x90,  0x90, 0xC3 }; //nop; nop; ret
void (*p)(void) =  (void(*)())     &program;
p();
Run Code Online (Sandbox Code Playgroud)

总是返回访问冲突.....

我正在使用visual studio 2012 C++ win32控制台应用程序

谢谢.

c++

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

访问私有成员c ++

在此代码中,为什么我可以访问对象的私有成员而没有编译器错误?

class Cents
{
private:
    int m_nCents;
public:
    Cents(int nCents=0)
    {
        m_nCents = nCents;
    }

    // Copy constructor
    Cents(const Cents &cSource)
    {
        m_nCents = cSource.m_nCents;
    }

    Cents& operator= (const Cents &cSource);

};

Cents& Cents::operator= (const Cents &cSource)
{
Run Code Online (Sandbox Code Playgroud)

cSource.m_nCents是私有的,为什么我可以执行以下操作:

    m_nCents = cSource.m_nCents;

    // return the existing object
    return *this;
}
Run Code Online (Sandbox Code Playgroud)

c++ private

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

使用指向char而不是char数组的错误

可能重复:
为什么简单的C代码会收到分段错误?

我在Ubuntu中使用GCC编译器和C语言; 我有这个程序:

void foo(char *word)
{
    //something stupid
    *word = 'z';
}

int main()
{

    char word1[] = "shoe";
    char *word2 = "shoe";

    foo(word1);
    printf("%s", word1);
    foo(word2);
    printf("%s", word2);
}
Run Code Online (Sandbox Code Playgroud)

那有什么区别?后者我得到一个segmentation fault错误.

c arrays pointers

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

算法从坐标中获取第一,第二,第三个邻居

在每个像素的位图中,我试图得到它的第一个,第二个,第三个......级别的邻居,直到位图结束,但我的解决方案有点慢,所以让我知道你们是否有人更好的算法或方法:

例

private IEnumerable<Point> getNeightboorsOfLevel(int level, Point startPos, Point[,] bitMap)
{
    var maxX = bitMap.GetLength(0);
    var maxY = bitMap.GetLength(1);
    if (level > Math.Max(maxX, maxY)) yield break;

    int startXpos = startPos.X - level;
    int startYpos = startPos.Y - level;
    int sizeXY = level * 2;

    var plannedTour = new Rectangle(startXpos, startYpos, sizeXY, sizeXY);
    var tourBoundaries = new Rectangle(0, 0, maxX, maxY);

    for(int UpTour  = plannedTour.X; UpTour<plannedTour.Width; UpTour++) 
        if (tourBoundaries.Contains(UpTour,plannedTour.Y)) 
            yield return bitMap[UpTour,plannedTour.Y];

    for(int RightTour  = plannedTour.Y; RightTour<plannedTour.Height;RightTour++)
        if (tourBoundaries.Contains(plannedTour.Right,RightTour)) 
            yield return bitMap[plannedTour.Right,RightTour]; …
Run Code Online (Sandbox Code Playgroud)

c# algorithm image image-processing

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

标签 统计

c++ ×2

algorithm ×1

arrays ×1

c ×1

c# ×1

image ×1

image-processing ×1

javascript ×1

jquery ×1

pointers ×1

private ×1