相关疑难解决方法(0)

错误:'ClassName'之前的预期类型说明符

shared_ptr<Shape> circle(new Circle(Vec2f(0, 0), 0.1, Vec3f(1, 0, 0)));

shared_ptr<Shape> rect(new Rect2f(Vec2f(0, 0), 5.0f, 5.0f, 0,
                                  Vec3f(1.0f, 1.0f, 0))              );
Run Code Online (Sandbox Code Playgroud)

我试图理解为什么以上不会编译.无论出于什么原因,当我尝试创建一个Rect2f实例(其中DOES继承自Shape指定shared_ptr模板参数的类时,就像Circle),我得到以下错误:

error: expected type-specifier before 'Rect2f'
error: expected ')' before 'Rect2f'
Run Code Online (Sandbox Code Playgroud)

关于这一切的一切都Circle shared_ptr很好.它没有问题; 它只是Rect2f导致问题的原因.

此外,传递给构造函数的值是有效的.

那么,这个问题会出现什么问题呢?我已经Rect.h包含了这个.为了简洁起见(并且我错过了该文件中可能影响此内容的内容),我将发布以下内容:

Rect.h

#pragma once

#include <QGLWidget>
#include <GL/glext.h>
#include <cmath>
#include <QDebug>
#include "Shape.h"
#include "Vec3f.h"
#include "rand.h"

const int DEFAULT_SQUARE_WIDTH = 5;
const int DEFAULT_SQUARE_HEIGHT = 5;

typedef enum {
    RC_TOPLEFT, …
Run Code Online (Sandbox Code Playgroud)

c++ pure-virtual shared-ptr

45
推荐指数
2
解决办法
15万
查看次数

标签 统计

c++ ×1

pure-virtual ×1

shared-ptr ×1