Basically I'm trying to generate 3 classes, each one relying on the previous one: 'Parameter' is independent, 'Segment' uses Parameter as variables and 'File' uses Segment as variables. However, I keep getting C2143 errors when calling 'Segment' in 'File', followed by C4430 errors because of them. Here's the code:
publicclass Parameter{
std::string name;
std::string value;
public:
Parameter(){
name = "";
value = "";
}
Parameter(std::string nameIN, std::string valueIN){
name = nameIN;
value = valueIN;
}
Parameter operator= (Parameter pIn){
name = pIn.name;
value = pIn.value;
}
void setValues(std::string nameIn, std::string valueIn){
name = nameIn;
value = valueIn;
}
void Value(std::string input){
value = input;
}
};
publicclass Segment{
Parameter * variable;
Parameter * temp;
int parameters;
std::string name;
public:
Segment(){
name = "";
parameters = 0;
}
Segment(std::string nameIN){
name = nameIN;
parameters = 0;
}
Segment operator= (Segment sIn){
name = sIn.name;
parameters = sIn.parameters;
}
void Add(std::string nameIN, std::string valueIN){
parameters++;
temp = new Parameter[parameters];
for(int i=0; i < (parameters-1); i++){
temp[i] = variable[i];
}
temp[parameters-1].setValues(nameIN,valueIN);
}
};
publicclass File{
Segment * segment; // C2143 error here (missing ';' before '*') - Line 183
Segment * temp; // C2143 error again - Line 184
int noSegments;
File(){
noSegments = 0;
}
AddSegment(std::string name){
noSegments++;
temp = new Segment[parameters];
for(int i=0; i < (noSegments-1); i++){
temp[i] = segment[i];
}
temp[noSegments-1] = new Segment(name);
}
};
The strange thing is, I originally had this problem when coding the 'Segment' class, but after renaming the 'Parameter' class from 'Variable' to 'Parameter' (I didn't change anything else), it worked without issue. Unfortunately, renaming Segment hasn't solved it....
I tried re-coding 'File' by using 'Parameter' and then 'Segment' classes as a template, but that didnt work. In the interests of trying anything to get it working, I copy and pasted the 'Parameter' class and relabel everything necessary as 'Segment' (so the *only* difference between the two is the name of the class) but the 'parameter' class still works but the 'segments' class still throws the same errors.
I'm completely lost as to where this error could be coming from, so thanks for any help anyone can give!
1> Main.cpp
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(183): error C2143: syntax error : missing ';' before '*'
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(183): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(183): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(184): error C2143: syntax error : missing ';' before '*'
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(184): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(184): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(190): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(197): warning C4183: 'AddSegment': missing return type; assumed to be a member function returning 'int'
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(192): error C2061: syntax error : identifier 'Segment'
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(194): error C2065: 'segment' : undeclared identifier
1>c:\users\hibblejaybob\software development\projects\driving simulator\driving simulator\LoadFiles.h(196): error C2061: syntax error : identifier 'Segment'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I've updated the code to show where lines 183 and 184 are too
I have to wonder, why do all your classes start with "public"? This is a Java thing to do, in C++ classes are just classes, you don't write anything before the word 'class' unless it's a template.
@LB + Disch - thanks, but the 'public' decelerations aren't causing any problems, the errors are in lines 183 and 184 and all the other errors come from them.
@ Disch - Thanks for pointing that out, that was an issue, but not one causing any errors.
The problem is that 'Segment' is not being recognised as a class when being called in 'File'
@modoran - I haven't finished coding the classes yet - I want to get them running in a basic form first, but thanks for the observation
Did you know? Mistakes on line A-B can cause errors on lines C-D, which is what I think is happening here. Remove the word 'public' from before each of your classes.
Ok, solved it - its seems that 'Segment' must be restricted from being used to define a class. The first thing I tried renaming it to must have been unavailable as well, but renaming it to 'Segments' seems to have have solved it.