Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Generator

HeHacz picture HeHacz · Nov 14, 2016 · Viewed 41.4k times · Source

i have a problem with following code:

Generator.h:

#pragma once
class Generator
{
public:
    friend class BagObject; 
    Generator(void);
    ~Generator(void);
    ...
    void generator(int);
private:
    BagObject *object;
    vector<BagObject> data; //Error c4430
};

and this is a error:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

there is 6 more errors but i believe that they should disappeared after solving this problem.

this is the cpp file. I couldn't paste it on the first time. Generator.cpp

#include "stdafx.h"
#include "Generator.h"
#include "BagObject.h"
#include <iostream>
#include <vector>
#include <ctime>

using namespace std;


Generator::Generator(void)
{
    srand(time(NULL));
}


Generator::~Generator(void)
{
    data.clear();
}

void Generator::generator(int ld)
{
    for (int i = 0; i<ld; i++)
{
    object = new BagObject(rand(),rand(),i);
    data.push_back(object);
    }
}


int main()
{
    Generator *g = new Generator;
    g->generator(10);
    return 0;
}

Answer

Vlad from Moscow picture Vlad from Moscow · Nov 14, 2016

Either you forgot to include header

#include <vector>

or forgot to write directive

using namespace std;

In any case it would be better to write

#include <vector>

//...

std::vector<BagObject> data;
^^^^^

You have to include the header <vector> in all headers where there is a reference to std::vector.