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 1502
"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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |