Reputation: 421
First, Parameter.h
:
#pragma once
#include <string>
class Parameter {
public:
Parameter();
~Parameter();
private:
string constValue;
string varName;
};
And Parameter.cpp
:
#include "Parameter.h"
using namespace std;
Parameter::Parameter() {};
Parameter::~Parameter() {};
I've brought these two files down to the barest of bones to get the errors that seem to be popping up. At the two private declarations for string
s, I get the two errors:
'constValue': unknown override specifier
missing type specifier - int assumed. Note: C++ does not support default-int
I've seen several questions with these errors, but each refers to circular or missing references. As I've stripped it down to what's absolutely required, I can see no circular references or references that are missing.
Any ideas?
Upvotes: 32
Views: 124669
Reputation: 7111
As @Pete Becker points out in the comments, you need to qualify the name string
as std::string
:
private:
std::string constValue;
std::string varName;
The compiler just doesn't know what you're talking about, and it's the equivalent of just writing:
SomeGreatType myMagicalUniversalType
The compiler just doesn't know what type that is unless you've declared, hence the error
missing type specifier - int assumed
You should read up about why you should avoid using namespace std;
.
With regards to your question in the comments:
In all the (working) classes I've written, I've never put in the std::, instead relying on the using namespace std; in the .cpp file. Why would this one be any different?
I can only infer that at some point before including "Parameter.h" that you had a using namespace std
. E.g.:
// SomeType.h
#using namespace std
...
// Parameter.cpp
#include "SomeType.h"
#include "Parameter.h"
The compiler compiles things top-to-bottom, and including essentially just replaces the #include
with the contents of that file
Upvotes: 28