Home expected class-name before '{' token, using inheritance: c++
Reply: 0

expected class-name before '{' token, using inheritance: c++

shaked sapir
1#
shaked sapir Published in 2018-01-12 23:15:03Z

I am trying to compile the following code:

1.  #ifndef C_LIBRARY_TO_PROLOG_PROLOGLIB_H
2.  #define C_LIBRARY_TO_PROLOG_PROLOGLIB_H
3.
4.  #include <iostream>
5.  #include <stdbool.h>
6.  #include <stdio.h>
7.  #include <stdlib.h>
8.
9.  template<class T>
10. class LIST_H{ 
11. protected:
12.    T *begin;  //  min_from<=from;
13.    T *end;    //  max_to>=to;
14.   public:
15.    LIST_H(): begin(new T[N]), end(begin + N){}
16.    enum { N = 5 };
17.    inline long size() { return end-begin; }
18.
19. protected:
20.    inline size_t gulp() { return gulp(size()); }
21.    static inline size_t gulp(size_t s) { return ((s<<0x2)|0x11)/3;}
22.    inline size_t grow() {
23.        size_t s = gulp();
24.        begin = new T[s];
25.        end = begin + s;
26.        return size();
27.    } 
28. };
29.
30. template<class T>
31. class LIST_HH : protected LIST_H{
32. private:
33.    T *from;      //  first-element; from!=(T*)0;
34.    T *to;         //  beyond-final-element; from!=(T*)0; to>=from 34
35. public:
36.    LIST_HH(): from(begin), to(end) {}
37.    inline T first() { return *from; }
38.    inline T last() { return to[-1]; }
39.    inline size_t grow();
40.    size_t n() { return to-from; }
41.    inline T prepend(const T& t) {
42.        if(places_before_first()){
43.            *--from = t;
44.        } else{
45.            grow();
46.            prepend(t);
47.        }
48.    }
49.    inline T append(const T& t) {
50.        if(places_after_last()){
51.            *to++ = t;
52.        } else{
53.            grow();
54.            append(t);
55.        }
56.    } protected:
57.    inline size_t places_before_first() { return from-begin; }
58.    inline size_t places_after_last() { return end-to; }
59. };
60.   
61.
62. #endif //C_LIBRARY_TO_PROLOG_PROLOGLIB_H

and got the following error:

prologLib.h:31:33: error: expected class-name before '{' token
 class LIST_HH : protected LIST_H{

Now, I saw in the past that this problem is kinda related to forward declaration, but this is the only 'h' file that I am working on, and I didn't see any solutions to forward declaration with templates+inheritance.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308932 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO