小编Mit*_*tch的帖子

自定义对象传染媒介

我试图创建一个头文件中定义的自定义对象的向量,然后在实际的cpp文件中初始化它们.我在Visual Studio中遇到以下错误:

error C2976: 'std::vector' : too few template arguments
error C2065: 'Particle' : undeclared identifier
error C2059: syntax error : '>'
Run Code Online (Sandbox Code Playgroud)

在下面的代码中,向量在Explosion.h中定义.

Particle.h:

#pragma once
class Particle : public sf::CircleShape {
public:
    float speed;
    bool alive;
    float vx;
    float vy;
    Particle(float x, float y, float vx, float vy, sf::Color color);
    ~Particle();
};
Run Code Online (Sandbox Code Playgroud)

Particle.cpp:

#include <SFML/Graphics.hpp>
#include "Particle.h"

Particle::Particle(float x, float y, float vx, float vy, sf::Color color) {
    // Inherited
    this->setPosition(x, y);
    this->setRadius(5);
    this->setFillColor(color);

    // Player Defined Variables
    this->speed …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance vector object sfml

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

标签 统计

c++ ×1

inheritance ×1

object ×1

sfml ×1

vector ×1