我如何使用C ++ 11功能,如委派构造函数在Visual C ++ 2012年11月CTP? [英] How can I use C++11 features like delegating constructors in Visual C++ November 2012 CTP?

查看:233
本文介绍了我如何使用C ++ 11功能,如委派构造函数在Visual C ++ 2012年11月CTP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了visual c ++ 2012年11月CTP,但似乎我做错了,因为我仍然不能使用委托构造函数

I installed visual c++ November 2012 CTP but it seems i do something wrong because i still can't use delegating constructors


  1. 我将平台工具集设置为:Microsoft Visual C ++编译器2012年11月CTP(v120_CTP_Nov2012)

  1. I set the Platform Toolset to : Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012)

p>

This is my code:

#pragma once

#include<string>

class Hero
{
private:
    long id;
    std::string name;
    int level;
    static long currentId;
    Hero(const Hero &hero); //disable copy constructor
    Hero& operator =(const Hero &hero); //disable assign operator
public:
    Hero();
    Hero(std::string name, int level);
    long GetId() const { return this->id; }
    std::string GetName() const { return this->name; }
    int GetLevel() const { return this->level; }
    void SetName(std::string name);
    void SetLevel(int level);
};


PS: 11和视觉工作室2012更受欢迎。感谢。

PS: Any tips regarding to c++11 and visual studio 2012 are more then welcomed. Thanks.

LE:这是实施文件:

LE: This is the implementation file:

#include"Hero.h"

long Hero::currentId = 0;

Hero::Hero(std::string name, int level):name(name), level(level), id(++currentId) 
{

}

Hero::Hero():Hero("", 0)
{

}

void Hero::SetName(const std::string &name) 
{
    this->name = name; 
}

void Hero::SetLevel(const int &level) 
{
    this->level = level; 
}



我在无参数构造函数上得到以下错误消息:
Hero不是非静态数据成员或类Hero的基类

I get the following error message on the parameterless constructor: "Hero" is not a nonstatic data member or base class of class "Hero"

推荐答案

IntelliSense,它不支持新的C ++ 11语言功能。请注意,错误讯息的全文内容如下:

The error message you quote is being reported by IntelliSense, which does not yet support the new C++11 language features. Note that the full text of the error message reads (emphasis mine):


IntelliSense :Hero不是非静态数据成员或类Hero的基类。

IntelliSense: "Hero" is not a nonstatic data member or base class of class "Hero"

11月CTP公布状态(强调


虽然提供了一个新的Platform Toolset以方便将编译器集成为Visual Studio 2012构建环境的一部分,但 VS 2012 IDE,Intellisense,调试器,静态分析和其他工具保持基本不变,并且尚未支持这些新的C ++ 11功能。

编译器 由November CTP更新,拒绝具有以下错误的代码:

The compiler, which is updated by the November CTP, rejects the code with the following errors:

error C2511: 'void Hero::SetName(const std::string &)' : overloaded member function not found in 'Hero'
    c:\jm\scratch\test.cpp(6) : see declaration of 'Hero'
error C2511: 'void Hero::SetLevel(const int &)' : overloaded member function not found in 'Hero'
    c:\jm\scratch\test.cpp(6) : see declaration of 'Hero'

这些错误是预期的,因为你的代码是错误的(参数 SetLevel SetName 它们的内联声明,并在其定义中引用)。当这些错误是固定的,编译器接受你的代码。

These errors are expected because your code is ill-formed (the parameters of SetLevel and SetName are passed by value in their inline declarations, and by reference in their definitions). When these errors are fixed, the compiler accepts your code.

这篇关于我如何使用C ++ 11功能,如委派构造函数在Visual C ++ 2012年11月CTP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆