开发者

What's wrong with this class?

开发者 https://www.devze.com 2023-03-19 12:30 出处:网络
I\'m trying to create a simple static C++ library that I can link it into a M开发者_如何学GoonoTouch app and invoke the functions via MonoTouch. I\'m trying to compile the static library in XCode and

I'm trying to create a simple static C++ library that I can link it into a M开发者_如何学GoonoTouch app and invoke the functions via MonoTouch. I'm trying to compile the static library in XCode and have this (edited since ildjarn fixes):

class MyClass
{
public:
    static int Get5() { return 5; }
    static int Get10() { return 10; }
};

I get the following error on the first line:

Expected '=', ',', ';', 'asm' or 'attribute' before 'MyClass'

Any ideas why?

As an aside can I compile a static library in Visual Studio and link it into a MonoTouch app or is that impossible?


Member accessibility decorators are followed by a colon in C++, like labels or switch cases --

class MyClass
{
public:
    static int Get5() { return 5; }
    static int Get10() { return 10; }
};

Also, accessibility decorators have no effect on namespace-scoped types in C++, so public class MyClass is nonsensical.


You are mixing Java with C++. Obmit the "public" before the class and change the other "public" to "public:"


class MyClass
{    
    public:
    int Get5()    
    {        
        return 5;    
    }    
    int Get10()    
    {        
       return 10;    
    }
};

Or probably you need to compile it with /clr compiler flag (with your original code).

0

精彩评论

暂无评论...
验证码 换一张
取 消