Reputation: 27
I have a very simple problem. I am trying to learn C++ and I'm having a little problem. Here's the code
system.h
#include <iostream>
#include "processor.h"
using namespace std;
class sys
{
public:
int id;
sys()
{
id=0;
}
};
processor.h
#include <iostream>
using namespace std;
class proc
{
public:
const sys* s1;
s1=new sys();
};
The error says
"error C2512: 'sys' : no appropriate default constructor available"
There is a default constructor.
I am a beginner at C++ so please explain what I am doing wrong. Thank You.
Upvotes: 0
Views: 272
Reputation: 114491
Since class proc
is using class sys
the include order should be the opposite:
// sys.h
class sys {
...
};
// process.h
#include "sys.h"
class proc {
...
};
Upvotes: 0
Reputation: 206546
const
members are special members and they must be initialized in the Member initialization list.proc() : s1(new sys())
{
}
Upvotes: 2