K
ken.carlino
From http://www.parashift.com/c++-faq-lite/references.html#faq-8.6, it
said "Use references when you can, and pointers when you have to."
And I need to convert this java class to c++:
public class Y {
public final int[] w
public Y(final List alist {
w = new int[alist.size()];
}
}
So I am thinking about create a Reference of stl:vector for my
attribute 'w'.
class Y
{
public:
Y
virtual ~Y();
vector<int>& w;
};
and in my constructor, i initialize it like this:
Y::Y(list<Z>& alist) :
w ( vector<int>(alist.size()) )
{
}
And I get this compilation error:
.../src/YMapData.cpp:9: error: invalid initialization of non-const
reference of type 'std::vector<int, std::allocator<int> >&' from a
temporary of type 'std::vector<int, std::allocator<int> >'
I appreciate if someone can tell me what did I do wrong.
said "Use references when you can, and pointers when you have to."
And I need to convert this java class to c++:
public class Y {
public final int[] w
public Y(final List alist {
w = new int[alist.size()];
}
}
So I am thinking about create a Reference of stl:vector for my
attribute 'w'.
class Y
{
public:
Y
virtual ~Y();
vector<int>& w;
};
and in my constructor, i initialize it like this:
Y::Y(list<Z>& alist) :
w ( vector<int>(alist.size()) )
{
}
And I get this compilation error:
.../src/YMapData.cpp:9: error: invalid initialization of non-const
reference of type 'std::vector<int, std::allocator<int> >&' from a
temporary of type 'std::vector<int, std::allocator<int> >'
I appreciate if someone can tell me what did I do wrong.