constructeur et erreur compilo
Bonsoir,
voilà je débute en C++, et j'en suis arrivé au chapitre des constructeurs et j'ai un petit souci dans ce programme qui implémente une pile en utilisant des tableau et un index. le programme est bidon c'est juste pour apprendre ;).
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <iostream>
using namespace std;
struct stackette
{
int arr[20];
int top;
};
class Stack
{
private :
stackette m_s;
public :
Stack () : m_s.top (-1)
{
}
int pop ()
{
return m_s.arr[m_s.top--];
}
int peek ()
{
return m_s.arr[m_s.top];
}
void push (int val)
{
m_s.arr[++m_s.top] = val;
}
};
int main ()
{
Stack stack1;
stack1.push (5);
stack1.push (6);
stack1.push (7);
cout << stack1.peek () << endl;
cout << stack1.peek () << endl;
cout << stack1.pop () << endl;
cout << stack1.pop () << endl;
return EXIT_SUCCESS;
} |
le compilateur me donne une erreur :
C:\Codeblocks_projects\c++\arrays\main.cpp||In constructor `Stack::Stack()':|
C:\Codeblocks_projects\c++\arrays\main.cpp|19|error: expected `(' before '.' token|
C:\Codeblocks_projects\c++\arrays\main.cpp|19|error: expected `{' before '.' token|
||=== Build finished: 2 errors, 0 warnings ===|
et je sais pas pouquoi (quoique tout me laisse à penser que c'est à cause de la liste d'initialisation avec la structure)
Merci