473,796 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array of pointers makes an error

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(in t 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_matier e,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::Thora ire(const char nomEnseignant[])
{
strcpy(m_nomEns eignant,nomEnse ignant);

//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 TenseignantErro r{};

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
6 1522
"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
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.********@com Acast.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
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.********@com Acast.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
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(in t 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_matier e,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::Thora ire(const char nomEnseignant[])
Again, use std::string instead of arrays.
{
strcpy(m_nomEns eignant,nomEnse ignant);

//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 TenseignantErro r{};

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
it's enough yeah... thanks!

"Victor Bazarov" <v.********@com Acast.net> a écrit dans le message de news:
WL************* ******@newsread 1.mlpsca01.us.t o.verio.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(in t 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_matier e,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::Thora ire(const char nomEnseignant[])


Again, use std::string instead of arrays.
{
strcpy(m_nomEns eignant,nomEnse ignant);

//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 TenseignantErro r{};

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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3336
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..
20
2979
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) struct, I am storing an array of 27 pointers and a void pointer that can point to anything. typedef struct trieNode { struct trieNode *children; // The children nodes void *obj; // The object stored } TrieNode;
204
13129
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 = {0,1,2,4,9};
15
3842
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> typedef struct _tnode_t { void *content; struct _tnode_t *kids;
23
7421
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
5
1666
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 <stdlib.h> #define dim 2
6
3554
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 I'm avoiding the use of fscanf and fgets to read in lines. I don't want to have to specify a temporary char* buffer to read in each line, and then have to concern myself with the (remote) possibility of overflows or with increasing the buffer...
7
8722
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 modular menu system up and running. My menus will have several varying numbers of options. This is the first time I've worked with something like this and just can't get it worked out. I've snipped a lot of unnecessary code to this smaller piece so...
2
2988
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 standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
33
7188
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 array, so im inputting the dimensions of those myself. The problem is that the output array (C=A*B) has as many rows as A and as many columns as B. I would think of initialising C with:
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.