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;
}
Other answers are correct, but cryptic. In plain English, your header does not know about BagObject
class. You included BagObject.h
in the .cpp
, but you should have included it in the .h
.
It also does not know about vector
for the same reason.
I am guessing, you were under impression that .cpp
had to use #include
, but .h
did not. This is a common misunderstanding of beginners in C++. Headers need to include all referenced class declarations, hence you need to elevate your includes from .cpp
into your .h
.
Move two mentioned includes into the header and it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With