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;
} 6 1492
"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
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
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
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
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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: James |
last post by:
Hi, I'm hoping someone can help me out.
If I declare a class, eg.
class CSomeclass
{
public:
var/func etc.....
private
varfunc etc..
|
by: fix |
last post by:
Hi all,
I feel unclear about what my code is doing, although it works but I am
not sure if there is any possible bug, please help me to verify it.
This is a trie node (just similar to tree nodes)...
|
by: Alexei A. Frounze |
last post by:
Hi all,
I have a question regarding the gcc behavior (gcc version 3.3.4).
On the following test program it emits a warning:
#include <stdio.h>
int aInt2 = {0,1,2,4,9,16};
int aInt3 =...
|
by: Paminu |
last post by:
Still having a few problems with malloc and pointers.
I have made a struct. Now I would like to make a pointer an array with 4
pointers to this struct.
#include <stdlib.h>
#include <stdio.h>...
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these...
|
by: =?ISO-8859-1?Q?Jonathan_Gro=DF?= |
last post by:
Hi everybody,
in the sample below my programm gives a "Bus error" on the marked line.
I don't get it why that happens. I followed the instructions in the
C-FAQ.
#include <math.h>
#include...
|
by: Kinbote |
last post by:
Hi,
I'm trying to make a function that opens a file, reads it in line by
line, puts each line into an malloc'd array, and returns the array. I
suspect I'm going about it in an atypical fashion, as...
|
by: roguefeebo |
last post by:
I'm very new to programming so be gentle, :(
Essentially what I would like to do is to have a single function to be able to create a dynamic array of pointers to a struct so that I can have a...
|
by: StevenChiasson |
last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller.
This is more or less, your...
|
by: Adam Chapman |
last post by:
Hi,
Im trying to migrate from programming in Matlab over to C. Im trying
to make a simple function to multiply one matrix by the other. I've
realised that C can't determine the size of a 2d...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |