小编Eri*_*son的帖子

Typescript导入类

我一直试图让这个东西工作很长一段时间,到目前为止我找不到任何解决方案对我有用.

这就是我所拥有的:

//Test.ts
module t
{
    export class Test
    {
        constructor ()
        {
            alert("test");
        }
    }
}

//Main.ts
/// <reference path="Test.ts" />

var test: t.Test = new t.Test();
Run Code Online (Sandbox Code Playgroud)

如你所见,我有两个文件,一个是Main.ts,另一个是Test.ts. 它们都在同一个文件夹中.如果它有助于我使用VS2012和Typescript插件.

感谢您的帮助!编辑:哦顺便说一下,我得到错误(在chrome中):未捕获的ReferenceError:t未定义

import class typescript

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

初始化列表:初始化时无法将“Participant”转换为“unsigned int”

尝试编译一个存储“参与者”的简单链表时,我遇到了一个非常奇怪的错误。但是我清楚地给了它正确的数据,这可以得到确认,因为它在不使用初始化列表时有效(执行赋值运算符“=”)。

下面是相关的代码块:

struct Participant
{
    unsigned startNumber;
    std::string forename;
    std::string surname;
    std::string club;
    float finishTime;
};

struct ListNode
{
    ListNode* next;
    Participant data;
};

Participant tempData {list->data}; //error occurs here.
Run Code Online (Sandbox Code Playgroud)

以下是我得到的错误:

List.cpp:15:36: error: cannot convert ‘Participant’ to ‘unsigned int’ in initialization
Run Code Online (Sandbox Code Playgroud)

更换:

Participant tempData {list->data};
Run Code Online (Sandbox Code Playgroud)

和:

Participant tempData = list->data;
Run Code Online (Sandbox Code Playgroud)

编译并顺利运行。

g++ (Debian 4.7.2-5) 4.7.2
CrunchBang (Debian 7 'Wheezy')
Run Code Online (Sandbox Code Playgroud)

关于问题出在哪里的任何想法?任何帮助是极大的赞赏!

最好的问候,埃里克·詹森

c++ gcc linked-list initializer-list c++11

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

访问违规阅读课堂上的位置

我是C++的新手,我一直在玩指针和类.我遇到了一个问题,到目前为止我还没有找到解决方案:

RAII.exe中0x77F87508(msvcr110d.dll)的未处理异常:0xC0000005:访问冲突读取位置0xCCCCCCC0.

它似乎与我访问一个我无法访问的指针有关.

Main.cpp的:

#include <memory>
#include <iostream>
#include "Example.hpp"

void example()
{
    Example e;
}

int main()
{
    example();
    std::cout << "Press any key to exit";
    std::cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Example.cpp:

#include "Example.hpp"

Example::Example()
{
    m_a = new int(1);
    m_b = new int(2);
    m_b = new int(3);
}

Example::~Example()
{
    delete m_a;
    delete m_b;
    delete m_c;
}
Run Code Online (Sandbox Code Playgroud)

Example.hpp:

#ifndef _EXAMPLE_HPP_
#define _EXAMPLE_HPP_

#include <memory>
#include <iostream>

class Example
{
private:
    int *m_a;
    int *m_b;
    int *m_c;
public:
    Example();
    ~Example(); …
Run Code Online (Sandbox Code Playgroud)

c++ memory runtime-error

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