TypeScript to C++

栏目: IT技术 · 发布时间: 4年前

内容简介:TypeScript2Cxx is licensed under the MIT license.Want to chat with other members of the TypeScript to C++ community?create file test.ts

TypeScript to C++

License

TypeScript2Cxx is licensed under the MIT license.

Chat Room

Want to chat with other members of the TypeScript to C++ community?

Quick Start

  1. Build Project
npm install
npm run build
  1. Compile test.ts

create file test.ts

class Person {
    protected name: string;
    constructor(name: string) { this.name = name; }
}

class Employee extends Person {
    private department: string;

    constructor(name: string, department: string) {
        super(name);
        this.department = department;
    }

    public get ElevatorPitch() {
        return `Hello, my name is ${this.name} and I work in ${this.department}.`;
    }
}

const howard = new Employee("Howard", "Sales");
console.log(howard.ElevatorPitch);
node __out\main.js test.ts

Now you have test.cpp and test.h

test.h:

#ifndef TEST_H
#define TEST_H
#include "core.h"

using namespace js;

class Person;
class Employee;

class Person : public object {
public:
    string name;

    Person(string name);
};

class Employee : public Person {
public:
    string department;

    Employee(string name, string department);
    virtual any get_ElevatorPitch();
    Employee(string name);
};

extern Employee* howard;
#endif

test.cpp:

#include "test.h"

using namespace js;

Person::Person(string name) {
    this->name = name;
}

Employee::Employee(string name, string department) : Person(name) {
    this->department = department;
}

any Employee::get_ElevatorPitch()
{
    return "Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S;
}

Employee::Employee(string name) : Person(name) {
}

Employee* howard = new Employee("Howard"_S, "Sales"_S);

void Main(void)
{
    console->log(howard->get_ElevatorPitch());
}

int main(int argc, char** argv)
{
    Main();
    return 0;
}
  1. Compile it.
cl /W3 /GR /EHsc /std:c++latest /Fe:test.exe /I ../cpplib ../cpplib/core.cpp test.cpp
  1. Run it.
test.exe

Result:

Hello, my name is Howard and I work in Sales.

Enjoy it.


以上所述就是小编给大家介绍的《TypeScript to C++》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

深入理解Java虚拟机

深入理解Java虚拟机

周志明 / 机械工业出版社 / 2011-6 / 69.00元

《深入理解Java虚拟机:JVM高级特性与最佳实践》内容简介:作为一位Java程序员,你是否也曾经想深入理解Java虚拟机,但是却被它的复杂和深奥拒之门外?没关系,本书极尽化繁为简之妙,能带领你在轻松中领略Java虚拟机的奥秘。本书是近年来国内出版的唯一一本与Java虚拟机相关的专著,也是唯一一本同时从核心理论和实际运用这两个角度去探讨Java虚拟机的著作,不仅理论分析得透彻,而且书中包含的典型案......一起来看看 《深入理解Java虚拟机》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

MD5 加密
MD5 加密

MD5 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具