Ctor不允许返回类型 [英] Ctor not allowed return type

查看:152
本文介绍了Ctor不允许返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

struct B
{
    int* a;
    B(int value):a(new int(value))
    {   }
    B():a(nullptr){}
    B(const B&);
}

B::B(const B& pattern)
{

}

我得到错误msg:

'错误1错误C2533:'B :: {ctor}':构造函数不允许返回类型

I'm getting err msg:
'Error 1 error C2533: 'B::{ctor}' : constructors not allowed a return type'

任何想法为什么?

PS我正在使用VS 2010RC

Any idea why?
P.S. I'm using VS 2010RC

推荐答案

您的 struct 后缺少一个分号$ c>定义。

You're missing a semicolon after your struct definition.

错误是正确的,构造函数没有返回类型。因为你缺少一个分号,整个结构体定义被视为一个函数的返回类型,如:

The error is correct, constructors have no return type. Because you're missing a semicolon, that entire struct definition is seen as a return type for a function, as in:

// vvv return type vvv
struct { /* stuff */ } foo(void)
{
}

添加您的分号:

struct B
{
    int* a;
    B(int value):a(new int(value))
    {   }
    B():a(nullptr){}
    B(const B&);
}; // end class definition

// ah, no return type
B::B(const B& pattern)
{

}

这篇关于Ctor不允许返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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