0
    //--------------------------------------------test.cpp

// g++ test.cpp -O3 -Wall -swc -o test.swc


#include <iostream>
#include <list>
#include <vector>
#include "AS3.h"
using namespace std;

//vector<float> vf;
list<float> vf;

static AS3_Val getSize(void* self, AS3_Val args)
{
    int num = vf.size();
    return AS3_Int(num);
}

int main()
{
    AS3_Val getSizeMethod = AS3_Function( NULL, getSize);

    AS3_Val result = AS3_Object( "getSize:AS3ValType", getSizeMethod); 

    AS3_Release( getSizeMethod );

    AS3_LibInit( result );

    return 0;
}




    //-------------------------------------------------test.as

// C:\alchemy\flex4\bin\mxmlc -library-path+=./test.swc -static-link-runtime-shared-libraries=true test.as 


package{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    import cmodule.test.CLibInit

    public class test extends Sprite{
        public function test() {
            var info:TextField = new TextField();
            this.addChild(info);


            var loader:CLibInit = new CLibInit();
            var lib:Object = loader.init();
            info.appendText("size:" + lib.getSize() + "\n");
        }
    }
}

- - - - - - - - - - - - - - - - - - -问题 - - - - - - ------

1.test.swf 无法运行,但是如果我使用vector,就可以了!
2.如果我将一些元素推回列表中,它可以运行,但是我得到的大小是错误的!

谁能帮我!谢谢!!!

4

1 回答 1

1

静态初始化程序在 Alchemy 中被破坏。要解决这个问题,您需要在 main() 中构建您的列表。例如,

list<float> vf;

变成

list<float> *vf;

在您的主体中,您需要创建它:

vf= new list<float>();

你的 getSize 方法会返回

int num = vf->size();
于 2012-03-26T21:49:53.353 回答