omg oh noes new err0r! C++ plz assist.

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
error C2143: syntax error : missing ';' before '<'


template <class datatype>
class clearArray<datatype> : public arrayClass<datatype> //this line.
{
public:
void clearArrayValues();
};

my current code
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
Originally posted by: NuclearFusi0n
int userChoiceType;
cin >> userChoiceType;
switch (userChoiceType)
{
case 1: {arrayClass<long> longArray;
break;}
case 2: {arrayClass<float> floatArray;
break;}
case 3: {arrayClass<double> doubleArray;
break;}
}


error C2360: initialization of 'longArray' is skipped by 'case' label




three errors, one for each class :(
try edited code.
 

VBboy

Diamond Member
Nov 12, 2000
5,793
0
0
Or don't do conditional declarations. Declare all vars prior to the switch.
 

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
Originally posted by: notfred
Is that the entire program, what line # do you get an error on?

here's the entire program if you feel like taking a look: Text file with a PNG extension

This is the assignment:

Design an array class that will accept longs, floats, and doubles.
The class should create an array of 25 values of a type to be
determined when the class is instantiated.

Provide methods that will allow the user to do the following:
1- view entire array,
2- view any particular element (for example, array[3], etc), and
3- change the value of any element.

Instantiate a class of each type and fill the array with values using
the random and seed functions .

Using inheritance, create a subclass that will allow the user to
clear the array (set all values to null) and, then, repopulate the
array if the user desires.

Ask the user if the array is to be repopulated. If the answer is yes,
then, use random and srand functions to repopulate. Have the subclass
work on the same type values as it's base class.

NO global primitive variables will be allowed. All primitives must be
of local scope.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: PrincessGuard
Link

Also, those 3 objects will go out of scope at the end of the switch statement anyway.

Yea, doesn't matter if you could declare them this way.
Declare a pointer to each type, then dynamically allocate them in the switch statement. Or don't worry about the memory, statically allocate them and forget about the switch statement.
Still seems kludgy though.
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
did the edited code not work from my earlier post?

int userChoiceType;
cin >> userChoiceType;
switch (userChoiceType)
{
case 1: {arrayClass<long> longArray;
break;}
case 2: {arrayClass<float> floatArray;
break;}
case 3: {arrayClass<double> doubleArray;
break;}
}

gcc has the same issue.
 

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
i'm declaring all of them at the beginning of main(), and the switch is choosing which one to operate on

damnit now i need to do a nested switch - this is going to be messy.
 

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
error C2143: syntax error : missing ';' before '<'


template <class datatype>
class clearArray<datatype> : public arrayClass<datatype> //this line.
{
public:
void clearArrayValues();
};

my current code
 

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
it's probably some stupid error that i'm missing - been up for about 48 hours with maybe 2 hours of sleep at the most. :(
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Isn't there suppsoed to be some type of punctuation after this line:

template <class datatype>

?

I don't know, I don't really write C++
 

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
Originally posted by: notfred
What was it?

my last switch statement, was calling the name of the class, not the name of the variable i declared
sort of like:

int x;
int++;

instead of

int x;
x++;



hehe ;)
 

Smilin

Diamond Member
Mar 4, 2002
7,357
0
0

A shot in the dark since you are getting desparate:

I had this once. It was expecting a ; because it didn't recognize my class. Turns out one of my includes was using some old C style syntax. I was using #include <string.h> instead of #include <string> or something like that.

Using namespace std?
 

NuclearFusi0n

Diamond Member
Jul 2, 2001
7,028
0
0
Originally posted by: Smilin
A shot in the dark since you are getting desparate:

I had this once. It was expecting a ; because it didn't recognize my class. Turns out one of my includes was using some old C style syntax. I was using #include <string.h> instead of #include <string> or something like that.

Using namespace std?
too late, bro. already finished, tested, and turned in. :)