小编Eli*_*iel的帖子

ts1206装饰器在这里无效,Angular 2

我开始编写Angular 2,我遇到了一个错误:

ts1206装饰器在这里无效

@Component({   //  ts1206 decorators are not valid here
  selector: 'my-app',
  moduleId: module.id,
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css']
})
Run Code Online (Sandbox Code Playgroud)

更新:

我的tsconfig.json:

 {
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

typescript angular

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

什么"默认定义将是不正确的"是指什么?

我是c ++的一个初学者,我试图创建一个对象,但我得到一个错误,我不明白什么是错的.我得到错误时这是我的hpp文件+ cpp文件:

Manager::Manager(const Manager &manager ) :
Worker(manager.name,manager.id,manager.salary){
   this->workers=manager.workers;
}

class Manager:public Worker {
    private:
    std::vector<Worker> workers;         
    public:
        Manager(const char* name, int id, int salary);
        Manager(const Manager &manager );      
};
Run Code Online (Sandbox Code Playgroud)

错误:

In file included from Manager.hpp:5:0,
                 from Manager.cpp:1:
Worker.hpp:7:7: note: ‘Worker& Worker::operator=(const Worker&)’ is implicitly deleted because the default definition would be ill-formed:
 class Worker{
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做它工作:

Manager::Manager(const Manager &manager ) :
    Worker(manager.name,manager.id,manager.salary), workers(manager.workers){
               }
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我为什么?


编辑:

这是worker类代码:

这是worker.hpp

  class Worker{
        protected:
            const std::string name;
            const int id;
            int salary; …
Run Code Online (Sandbox Code Playgroud)

c++

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

这个字符串会被打印多少次?

我在考试中看到了这段代码:问题是这个字符串的打印次数.

我首先想到它会是10次,但这是错误的.有人能告诉我为什么我的答案是错的.这是C语言代码的一部分.

for (float x = 100000001.0f; x <= 100000010.0f; x += 1.0f) {
    printf("lbc");
}
Run Code Online (Sandbox Code Playgroud)

c

3
推荐指数
2
解决办法
143
查看次数

operator <<必须只取一个参数

我写的类有错误,我不明白是什么问题.

这是工人阶级:

#ifndef __Worker__
#define __Worker__

#include <iostream>
#include <string> 

class Worker{
    protected:
        std::string name;
        int id;
        int salary;

    public:
        Worker(const std::string& name, int id, int salary);
        Worker(const Worker& worker );
        friend std::ostream& operator<<(std::ostream& os, const Worker& w);
        int getWorkerID(){
            return this->id;
        }
        int getsSalary(){
            return this->salary;
        }
        std::string getname(){
            return this->name;
        }

};
#endif
Run Code Online (Sandbox Code Playgroud)

这是这个类的实现:

#include "Worker.hpp"

Worker::Worker(const std::string &names, int ids, int salarys) :
name(names), id(ids), salary(salarys)
{
}

Worker::Worker(const Worker &worker): 
name(worker.name), id(worker.id), salary(worker.salary)
{

}


std::ostream& …
Run Code Online (Sandbox Code Playgroud)

c++

-1
推荐指数
1
解决办法
1712
查看次数

C++中的构造函数错误

我刚刚开始学习cpp.我创建了一个包含2个构造函数的类.当我在ubuntu上运行此命令时: g++ -Wall -g main.cpp car.cpp -o a 我收到错误按摩:

> "In file included from main.cpp:2:0: car.h:10:15: 
error: expected ‘)’ before ‘,’ token  car(string,string,int);

In file included from car.cpp:1:0: car.h:10:15: 
error: expected ‘)’ before ‘,’ token car(string,string,int);

car.cpp:10:9: error: expected constructor, destructor, or type conversion before ‘(’ token  car::car(string brand, string color, int cost){  "
Run Code Online (Sandbox Code Playgroud)

我不明白为什么我收到此错误信息,我的代码有什么问题?请帮我.

这是我的代码:

这是一个h文件

#include <iostream>
#include <string>
#pragma once

class car{

    public:
    car();
    car(string,string,int);
    int get_cost();
    std::string get_brand();
    std::string get_color();

    private:
    std::string newbrand;
    std::string newcolor;
    int …
Run Code Online (Sandbox Code Playgroud)

c++

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

标签 统计

c++ ×3

angular ×1

c ×1

typescript ×1