H
hardwareman
Hi All,
I've read that I should use references instead of pointers, and as I do
have some suspicious casts floating around in my code, I thought it a
good idea to remove them. Ultimate datastructure is a map of Vectors
of references ((sb_iter->second)[0])->GetPktId(),
I wish to have a vector of object references instead of of a vector of
pointers to the objects e.g.:
typedef vector<PKT &> PKTchain_T ; <-- doesn't compile
typedef vector<PKT *> PKTchain_T ; <-- works fine
TESTCASE yields many errors like:
/usr/include/c++/3.2.2/bits/stl_vector.h:115: forming pointer to
reference type
Is this a case where I should stick with the pointers?
--- TESTCASE START ---
#include <map>
#include <vector>
#include <stdio.h>
using namespace std ;
typedef vector<int &> VINT_T ;
VINT_T vint(20) ;
int main () {
return 0 ;
}
--- TESTCASE END ---
removing the & in the typedef compiles fine :
typedef vector<int > VINT_T ;
I've read that I should use references instead of pointers, and as I do
have some suspicious casts floating around in my code, I thought it a
good idea to remove them. Ultimate datastructure is a map of Vectors
of references ((sb_iter->second)[0])->GetPktId(),
I wish to have a vector of object references instead of of a vector of
pointers to the objects e.g.:
typedef vector<PKT &> PKTchain_T ; <-- doesn't compile
typedef vector<PKT *> PKTchain_T ; <-- works fine
TESTCASE yields many errors like:
/usr/include/c++/3.2.2/bits/stl_vector.h:115: forming pointer to
reference type
Is this a case where I should stick with the pointers?
--- TESTCASE START ---
#include <map>
#include <vector>
#include <stdio.h>
using namespace std ;
typedef vector<int &> VINT_T ;
VINT_T vint(20) ;
int main () {
return 0 ;
}
--- TESTCASE END ---
removing the & in the typedef compiles fine :
typedef vector<int > VINT_T ;