By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

Array of pointers makes an error

P: n/a
Can someone tell me what's wrong with my code here?
When compiling, it says :

error C2143: syntax error : missing ';' before '*'
error C2501: 'Tcase' : missing storage-class or type specifiers
error C2501: 'm_cases' : missing storage-class or type specifiers

the compiler points out the problem on this:
Tcase* m_cases[CcasesMax];

it is in the class Thoraire.

here is my code.

#include "case.h"

Tcase::Tcase(int numSemaine, int numJour, double heureDebut, double duree,
char matiere[], char classe[], char salle[]) // pas de val par défaut ici!
{
m_numSemaine = numSemaine;
m_numJour = numJour;
m_heureDebut = heureDebut;
m_duree = duree;
strcpy(m_matiere,matiere);
strcpy(m_classe,classe);
strcpy(m_salle,salle);

}
#ifndef CASE_H
#define CASE_H

#include <iostream>
#include <iomanip>
#include <cstring>

#include "horaire.h"

using namespace std;

const int Clundi=1;
const int Cmardi=2;
const int Cmercredi=3;
const int Cjeudi=4;
const int Cvendredi=5;
const int Csamedi=6;
const int Cdimanche=7;
class Tcase{

public:

Tcase(int numSemaine, int numJour, double heureDebut, double duree,
char matiere[]=" ", char classe[]=" ", char salle[]=" ");

private:

int m_numSemaine;
int m_numJour;
double m_heureDebut;
double m_duree;
char m_matiere[10];
char m_classe[10];
char m_salle[10];

};

#endif
#include "horaire.h"
#include "case.h"

Thoraire::Thoraire(const char nomEnseignant[])
{
strcpy(m_nomEnseignant,nomEnseignant);

//m_cases=NULL;

m_nbCases=0;
}

#ifndef CASE_H
#define CASE_H

#include <iostream>
#include <iomanip>
#include <cstring>

#include "case.h"

using namespace std;

class TenseignantError{};

class Toverflow{};

const int CcasesMax=1000;

class Thoraire{

public:

Thoraire(const char nomEnseignant[]);

private:

char m_nomEnseignant[30];
Tcase* m_cases[CcasesMax];
int m_nbCases;
};

#endif

// main

#include <iostream>
using namespace std;

#include "case.h"
#include "horaire.h"
int main ()
{
Tcase case1(20,1,8,1.5,"programation");
return 0;
}


Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Stephane Vollet" <st*************@bluewin.ch> wrote...
Can someone tell me what's wrong with my code here?
Plenty. But I will only point out one mistake.
[..]
here is my code.
[...]
#ifndef CASE_H
#define CASE_H
[..]
#ifndef CASE_H
#define CASE_H
[..]


Notice anything strange?

V
Jul 23 '05 #2

P: n/a
OK thanks! I corrected it and now it compiles ok.

You send plenty of things wrong... what are the few others things wrong in
that code?

"Victor Bazarov" <v.********@comAcast.net> a écrit dans le message de news:
S4********************@comcast.com...
"Stephane Vollet" <st*************@bluewin.ch> wrote...
Can someone tell me what's wrong with my code here?


Plenty. But I will only point out one mistake.
[..]
here is my code.
[...]
#ifndef CASE_H
#define CASE_H
[..]
#ifndef CASE_H
#define CASE_H
[..]


Notice anything strange?

V

Jul 23 '05 #3

P: n/a
I meant:

You said there was plenty of things wrong... what are the few others things
wrong in
that code?

thank you.

"stephane" <st*************@bluewin.ch> a écrit dans le message de news:
41**********************@news.sunrise.ch...
OK thanks! I corrected it and now it compiles ok.

You send plenty of things wrong... what are the few others things wrong in
that code?

"Victor Bazarov" <v.********@comAcast.net> a écrit dans le message de
news: S4********************@comcast.com...
"Stephane Vollet" <st*************@bluewin.ch> wrote...
Can someone tell me what's wrong with my code here?


Plenty. But I will only point out one mistake.
[..]
here is my code.
[...]
#ifndef CASE_H
#define CASE_H
[..]
#ifndef CASE_H
#define CASE_H
[..]


Notice anything strange?

V


Jul 23 '05 #4

P: n/a
Stephane Vollet wrote:
Can someone tell me what's wrong with my code here?
When compiling, it says :

error C2143: syntax error : missing ';' before '*'
error C2501: 'Tcase' : missing storage-class or type specifiers
error C2501: 'm_cases' : missing storage-class or type specifiers

the compiler points out the problem on this:
Tcase* m_cases[CcasesMax];

it is in the class Thoraire.

here is my code.

#include "case.h"

Tcase::Tcase(int numSemaine, int numJour, double heureDebut, double duree,
char matiere[], char classe[], char salle[]) // pas de val par défaut ici!
Since you asked what it was I considered wrong, here you go...

First and foremost, you should use 'std::string' instead of fixed-length
arrays of char. That will save you lots of trouble in the days ahead.

Second, prefer initialisation over assignment. Read about it in the FAQ.
{
m_numSemaine = numSemaine;
m_numJour = numJour;
m_heureDebut = heureDebut;
m_duree = duree;
strcpy(m_matiere,matiere);
strcpy(m_classe,classe);
strcpy(m_salle,salle);
Third, if somebody passes in an array longer than 10 characters, you're
screwed (this is how Windows gets broken/cracked/open). Use 'strncpy'
instead since your 'm_' arrays are only 10 characters long.

}
#ifndef CASE_H
#define CASE_H

#include <iostream>
#include <iomanip>
#include <cstring>

#include "horaire.h"

using namespace std;
Putting a 'using' directive in the header is a VERY BAD IDEA(tm). Read
about that in the archives.

const int Clundi=1;
const int Cmardi=2;
const int Cmercredi=3;
const int Cjeudi=4;
const int Cvendredi=5;
const int Csamedi=6;
const int Cdimanche=7;
class Tcase{

public:

Tcase(int numSemaine, int numJour, double heureDebut, double duree,
char matiere[]=" ", char classe[]=" ", char salle[]=" ");
If you expect to pass default pointers to literals, you should declare
your constructor as accepting pointers to const:

...
char const *matiere = " ", char const *classe = " ", char const* ..

And as you can see I dropped the '[]' and put the '*' in there. Why?
Because I don't want to kid myself that the argument is an array. It
isn't, it's just a pointer. The notation "[]" is an alternative to
pointer, and really should be avoided IMO.

private:

int m_numSemaine;
int m_numJour;
double m_heureDebut;
double m_duree;
char m_matiere[10];
char m_classe[10];
char m_salle[10];

};

#endif
#include "horaire.h"
#include "case.h"

Thoraire::Thoraire(const char nomEnseignant[])
Again, use std::string instead of arrays.
{
strcpy(m_nomEnseignant,nomEnseignant);

//m_cases=NULL;

m_nbCases=0;
}

#ifndef CASE_H
#define CASE_H

#include <iostream>
#include <iomanip>
#include <cstring>

#include "case.h"

using namespace std;

class TenseignantError{};

class Toverflow{};

const int CcasesMax=1000;

class Thoraire{

public:

Thoraire(const char nomEnseignant[]);

private:

char m_nomEnseignant[30];
Tcase* m_cases[CcasesMax];
int m_nbCases;
};

#endif

// main

#include <iostream>
using namespace std;

#include "case.h"
#include "horaire.h"
int main ()
{
Tcase case1(20,1,8,1.5,"programation");
return 0;
}


Enough for now, I guess.

V
Jul 23 '05 #5

P: n/a
it's enough yeah... thanks!

"Victor Bazarov" <v.********@comAcast.net> a écrit dans le message de news:
WL*******************@newsread1.mlpsca01.us.to.ver io.net...
Stephane Vollet wrote:
Can someone tell me what's wrong with my code here?
When compiling, it says :

error C2143: syntax error : missing ';' before '*'
error C2501: 'Tcase' : missing storage-class or type specifiers
error C2501: 'm_cases' : missing storage-class or type specifiers

the compiler points out the problem on this:
Tcase* m_cases[CcasesMax];

it is in the class Thoraire.

here is my code.

#include "case.h"

Tcase::Tcase(int numSemaine, int numJour, double heureDebut, double duree, char matiere[], char classe[], char salle[]) // pas de val par défaut
ici!
Since you asked what it was I considered wrong, here you go...

First and foremost, you should use 'std::string' instead of fixed-length
arrays of char. That will save you lots of trouble in the days ahead.

Second, prefer initialisation over assignment. Read about it in the FAQ.
{
m_numSemaine = numSemaine;
m_numJour = numJour;
m_heureDebut = heureDebut;
m_duree = duree;
strcpy(m_matiere,matiere);
strcpy(m_classe,classe);
strcpy(m_salle,salle);


Third, if somebody passes in an array longer than 10 characters, you're
screwed (this is how Windows gets broken/cracked/open). Use 'strncpy'
instead since your 'm_' arrays are only 10 characters long.

}
#ifndef CASE_H
#define CASE_H

#include <iostream>
#include <iomanip>
#include <cstring>

#include "horaire.h"

using namespace std;


Putting a 'using' directive in the header is a VERY BAD IDEA(tm). Read
about that in the archives.

const int Clundi=1;
const int Cmardi=2;
const int Cmercredi=3;
const int Cjeudi=4;
const int Cvendredi=5;
const int Csamedi=6;
const int Cdimanche=7;
class Tcase{

public:

Tcase(int numSemaine, int numJour, double heureDebut, double duree,
char matiere[]=" ", char classe[]=" ", char salle[]=" ");


If you expect to pass default pointers to literals, you should declare
your constructor as accepting pointers to const:

...
char const *matiere = " ", char const *classe = " ", char const* ..

And as you can see I dropped the '[]' and put the '*' in there. Why?
Because I don't want to kid myself that the argument is an array. It
isn't, it's just a pointer. The notation "[]" is an alternative to
pointer, and really should be avoided IMO.

private:

int m_numSemaine;
int m_numJour;
double m_heureDebut;
double m_duree;
char m_matiere[10];
char m_classe[10];
char m_salle[10];

};

#endif
#include "horaire.h"
#include "case.h"

Thoraire::Thoraire(const char nomEnseignant[])


Again, use std::string instead of arrays.
{
strcpy(m_nomEnseignant,nomEnseignant);

//m_cases=NULL;

m_nbCases=0;
}

#ifndef CASE_H
#define CASE_H

#include <iostream>
#include <iomanip>
#include <cstring>

#include "case.h"

using namespace std;

class TenseignantError{};

class Toverflow{};

const int CcasesMax=1000;

class Thoraire{

public:

Thoraire(const char nomEnseignant[]);

private:

char m_nomEnseignant[30];
Tcase* m_cases[CcasesMax];
int m_nbCases;
};

#endif

// main

#include <iostream>
using namespace std;

#include "case.h"
#include "horaire.h"
int main ()
{
Tcase case1(20,1,8,1.5,"programation");
return 0;
}


Enough for now, I guess.

V

Jul 23 '05 #6

P: n/a
"Stephane Vollet" <st*************@bluewin.ch> wrote in message
news:41**********@news.bluewin.ch...
it's enough yeah... thanks!


A good way you can thank Victor (and all the regulars
here) for their help is to not top-post, and delete any
unnecessary text from your reply. Leave only enough
to preserve context. Thanks.

-Mike
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.