Error C2143 issues

Hi Everyone,

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public class 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;
     }
 };

public class 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);
     }
 };

public class 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!
Last edited on
Could you copy and paste the error message? "C2143" is completely irrelevent to helping you.
http://msdn.microsoft.com/en-us/library/0afb82ta.aspx
It's also important to know which line numbers are the culprit.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
1
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.
+1 LB

Get rid of the "public" before your classes. Not needed in C++.

Also, you need to give File::AddSegment a return type (probably void?)
Also be aware of memory leaks. You have used "new" operator without correspondind "delete".
@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.
Last edited on
I'm aware of that LB - I said what I said before because I tried removing the 'public' part from the code and it still did not work
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.
Topic archived. No new replies allowed.