List of sliders with template

Pages: 12

1
2
typedef typename ListaCur<T>::ComponenteSpazio<T> ComponenteSpazio<T>;
static ComponenteSpazio<T> SPAZIO[MAXLUNG]; //21 errors 
static ComponenteSpazio<T> SPACE [100];
did that do the trick?

typedef typename ListaCur<T>::ComponenteSpazio<T> SPAZIO;
ComponenteSpazio is not nested inside ListaCur so that does not make sense, don't write ListaCur<T>:: if it is not a nested class.
Ok, so I have to create a nested class. I said
ComponenteSpazio <T> SPACE [MAXLUNG];
before the 'main' and errors were reduced from 34 to 14.
But if you do not create a separate header file for the class template ComponenteSpazio <T>, you not lost in abstraction?
forget about that nested stuff for a second, try this:

1
2
typedef typename ComponenteSpazio<T> SPAZIO; // SPAZIO is now a type
static SPAZIO Space[MAXLUNG]; // create array of type SPAZIO 

(you might have to remove the typename)
Last edited on
1
2
3

template<class T>         //static ComponenteSpazio<T>* ListaCur<T>::inizializza(){
typename ListaCur<T>::ComponenteSpazio<T> *ListaCur<T>::inizializza(){


//[Error] non-template 'ComponenteSpazio' used as template
//[Note] use 'ListaCur<T>::template ComponenteSpazio' to indicate that it is a template

I replaced:

typename ListaCur<T>::template ComponenteSpazio * ListaCur<T>::inizializza(){

//errors 15
[Error] expected template-id before 'ComponenteSpazio'
[Error] prototype for 'typename ListaCur<T>::ComponenteSpazio* ListaCur<T>::inizializza()' does not match any in class 'ListaCur<T>'

[Error] candidate is: static ComponenteSpazio<T>* ListaCur<T>::inizializza()

//errors 21
[Error] cannot declare member function 'static ComponenteSpazio<T>* ListaCur<T>::inizializza()' to have static linkage [-fpermissive]
if you want to test:
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
#include <cstdlib>
#include <iostream>
#include "Nodo.h"
#include "NodoCur.h"
#include "ListaCur.h"
#include "linear_list.h"
using namespace std;
 
int main(int argc, char *argv[])
{
	ListaCur<int> lista;
	bool e = false;
	e=lista.empty();
	if(e)	
	   cout<<"lista vuota"<< endl;
	else    
	   cout <<"lista non vuota"<< endl;
	
	int p=0;
	p =	lista.begin();
	
	cout<<"lista.begin()= " << p<<endl;
	int a;
	a=lista.previous(p);
	cout<<"lista.previous(p)="<<a<<endl;
	lista.~ListaCur();
 
   system("PAUSE");
   return 0;
}
ListaCur<T>::ComponenteSpazio<T>
Holy shit man, are you even listening?
Just remove that damned ListaCur<T>:: before ComponenteSpazio.
ComponenteSpazio is not declared inside of ListaCur so it doesn't make any sense to write it like this.


1
2
template<class T>        
typename ComponenteSpazio<T> *ListaCur<T>::inizializza()
Last edited on
sorry it will be the fatigue that makes me commit careless mistakes

template<class T>
//typename ComponenteSpazio<T> *ListaCur<T>::inizializza(){
typename ComponenteSpazio<T> inizializza(){

[Error] expected nested-name-specifier
you can omit that typename now because it's not a type declared in ListaCur<T> anymore.
I had already tried, but the errors become 18.

1
2
3
4
template<class T>        
ComponenteSpazio<T> *ListaCur<T>::inizializza(){   

	SPAZIO = new ComponenteSpazio<T>[MAXLUNG];


[Error] expected unqualified-id before '=' token
This error has nothing todo with the typename.
What is SPAZIO?
where is it declared?
No, they were stupid mistakes that I corrected.

1
2
template<class T>                    
ComponenteSpazio<T> *SPAZIO Space= inizializza();


[Error] expected initializer before 'Space'
that's an other stupid mistake
did you define SPAZIO somewhere?
If not, what seems to be the case, just remove it.
1
2
template<class T>                    
ComponenteSpazio<T> *Space= inizializza();
I had already tried, but always gives me errors.
You can not attach screenshots?
If I write:

1
2
template<class T>                    
ComponenteSpazio<T> *Space= inizializza();


20errors
[Error] template declaration of 'ComponenteSpazio<T>* Space'

If I write:
 
*Space= inizializza();


18errors
[Error] expected constructor, destructor, or type conversion before '=' token

If I write:
 
*Space= ListaCur<T>::inizializza();


18errors
[Error] expected constructor, destructor, or type conversion before '=' token

Then he tells me that are not allowed to 'previous' and 'next' because they are private, but if I make them public, I lose abstraction.
don't count the errors.
It won't get you anything.

1
2
template<class T>   
ComponenteSpazio<T> *Space= inizializza();

Do you declare a method that way?
Why the =?
Last edited on
The method has been declared here:

1
2
3
4
5
6
7
8
9
template<class T>
class ListaCur : public Linear_list<T, int>{
public:
          ...
private:
...
static ComponenteSpazio<T> * inizializza();  
...
};


While the method has been defined here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


template<class T>        
ComponenteSpazio<T> *ListaCur<T>::inizializza(){   

	SPAZIO Space= ComponenteSpazio<T>()[MAXLUNG];
    if (!inizializzato){
	  Space[0].precedente= MAXLUNG-1;
	  Space[0].successivo= 1;
	  for (int i=1;i<MAXLUNG;i++){
	     Space[i].precedente=(i-1)%MAXLUNG;
		 Space[i].successivo=(i+1)%MAXLUNG;
      }
	  inizializzato=true;
	  cout << "spazio inizializzato" << endl;
	  return(Space);
   }
}


To initialize the array 'Space' I apply the method 'Initialize ()', that's what I need the equals '='

1
2
template<class T>   
ComponenteSpazio<T> *Space= inizializza();


So where I made a mistake?
I do not want to declare the method, I'm using it. I'm applying for him to return an array initialized to pointer 'Space'.
Really many thanks for everything, it was a pleasure, bye.
Topic archived. No new replies allowed.
Pages: 12