I'm doing a class who takes in constructor a vector<int> keeps and makes
some statistic on the vector whitout modifiing it.
I would like not to make a copy of the vector for the class. to let the full
process be faster a smaller in memory.
I tried to pass the vector by reference using * but that operator doesn't
exist.
my ask is: how the vector are passed to functions?
thanx alot
Giulio 8 9113
passing simply the vectors I need it makes me an error in the while
argument.
how to solve this?
thanx
Giulio
---------------------------------
std::vector<tipi::prezzo>::iterator pr = prezzo_.begin();
std::vector<tipi::operazione>::iterator op = op_.begin();
std::vector<tipi::prezzo>::iterator finePr = prezzo_.end();
std::vector<tipi::operazione>::iterator fineOp = op_.end();
while( op!=finePr && pr!=fineOp ) {
---------------------------------
Compiler: Default compiler
Building Makefile: "G:\bor\Makefile.win"
Executing make...
make.exe -f "G:\borsa\Makefile.win" all
g++.exe -D__DEBUG__ -c valuta.cpp -o
aluta.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C
:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include" -g3
valuta.cpp: In member function `attendibilita valuta::getAttendibilita()':
valuta.cpp:33: no match for `__gnu_cxx::__normal_iterator<operazione*,
std::vector<operazione, std::allocator<operazione> > >& !=
__gnu_cxx::__normal_iterator<prezzo*, std::vector<prezzo,
std::allocator<prezzo> > >&' operator
C:/Dev-Cpp/include/objbase.h:64: candidates are: BOOL operator!=(const
GUID&,
const GUID&)
valuta.cpp:33: no match for `__gnu_cxx::__normal_iterator<prezzo*,
std::vector<prezzo, std::allocator<prezzo> > >& !=
__gnu_cxx::__normal_iterator<operazione*, std::vector<operazione,
std::allocator<operazione> > >&' operator
C:/Dev-Cpp/include/objbase.h:64: candidates are: BOOL operator!=(const
GUID&,
const GUID&)
valuta.cpp:45: warning: assignment to `int' from `attendibilita'
valuta.cpp:45: warning: argument to `int' from `attendibilita'
make.exe: *** [valuta.o] Error 1
Execution terminated
-----------------------------------
Giulio <giulio.gL E V A@email.it> wrote in message
news:oU*******************@tornado.fastwebnet.it.. . I'm doing a class who takes in constructor a vector<int> keeps and makes some statistic on the vector whitout modifiing it.
I would like not to make a copy of the vector for the class. to let the
full process be faster a smaller in memory.
I tried to pass the vector by reference using * but that operator doesn't exist. my ask is: how the vector are passed to functions?
Example:
SomeClass::SomeClass(const vector<int> &v)
{
vector<int>::const_iterator iv = v.begin();
while(iv != v.end())
{
// do something
++iv;
}
}
David
Giulio <giulio.gL E V A@email.it> wrote in message
news:X%*******************@tornado.fastwebnet.it.. . passing simply the vectors I need it makes me an error in the while argument. how to solve this?
thanx Giulio --------------------------------- std::vector<tipi::prezzo>::iterator pr = prezzo_.begin(); std::vector<tipi::operazione>::iterator op = op_.begin(); std::vector<tipi::prezzo>::iterator finePr = prezzo_.end(); std::vector<tipi::operazione>::iterator fineOp = op_.end();
while( op!=finePr && pr!=fineOp ) {
--------------------------------- Compiler: Default compiler Building Makefile: "G:\bor\Makefile.win" Executing make... make.exe -f "G:\borsa\Makefile.win" all g++.exe -D__DEBUG__ -c valuta.cpp -o
luta.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C :/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include" -g3
valuta.cpp: In member function `attendibilita valuta::getAttendibilita()': valuta.cpp:33: no match for `__gnu_cxx::__normal_iterator<operazione*, std::vector<operazione, std::allocator<operazione> > >& != __gnu_cxx::__normal_iterator<prezzo*, std::vector<prezzo, std::allocator<prezzo> > >&' operator C:/Dev-Cpp/include/objbase.h:64: candidates are: BOOL operator!=(const GUID&, const GUID&) valuta.cpp:33: no match for `__gnu_cxx::__normal_iterator<prezzo*, std::vector<prezzo, std::allocator<prezzo> > >& != __gnu_cxx::__normal_iterator<operazione*, std::vector<operazione, std::allocator<operazione> > >&' operator C:/Dev-Cpp/include/objbase.h:64: candidates are: BOOL operator!=(const GUID&, const GUID&) valuta.cpp:45: warning: assignment to `int' from `attendibilita' valuta.cpp:45: warning: argument to `int' from `attendibilita'
Looks like type mismatches, but it's hard to tell exactly where. Please post
the definitions of tipi::prezzo, tipi::operazione, prezzo_ and op_ and it
might be easier to see what is wrong.
David
Giulio <giulio.gL E V A@email.it> wrote in message
news:oU*******************@tornado.fastwebnet.it.. . I'm doing a class who takes in constructor a vector<int> keeps and makes some statistic on the vector whitout modifiing it.
I would like not to make a copy of the vector for the class. to let the
full process be faster a smaller in memory.
I tried to pass the vector by reference using * but that operator doesn't exist.
The * operator does indeed exist, but what you're after
is a reference:
#include <vector>
class X
{
public:
X(const std::vector<int>& arg) : v(arg) { }
private:
const std::vector<int>& v;
}; my ask is: how the vector are passed to functions?
You can pass them by value, by reference, or by pointer.
-Mike
"Giulio" <giulio.gL E V A@email.it> wrote in message
news:oU*******************@tornado.fastwebnet.it.. . I'm doing a class who takes in constructor a vector<int> keeps and makes some statistic on the vector whitout modifiing it.
I would like not to make a copy of the vector for the class. to let the
full process be faster a smaller in memory.
I tried to pass the vector by reference using * but that operator doesn't exist.
What you're saying is pass a reference to a pointer:
void f (std::vector<int>& *a);
which is certainly not what you meant. You meant to say pass the vector by
reference, or pass it using *, not both. my ask is: how the vector are passed to functions?
thanx alot
Giulio
Not quite sure why your compiler wouldn't let you point to the vector, it is
perfectly legal:
void f(const std::vector<int> *a);
but what you probably wanted was a constant reference to the vector:
void f(const std::vector<int> &a);
which allows you not to copy the vector, and ensure it doesn't change.
Moreover, it is much faster, as you wanted. And, unlike pointers, it doesn't
deal with mucking about with dereferencing, etc.
-- MiniDisc_2k2
To reply, replace nospam.com with cox dot net.
Giulio wrote: passing simply the vectors I need it makes me an error in the while argument. how to solve this?
thanx Giulio --------------------------------- std::vector<tipi::prezzo>::iterator pr = prezzo_.begin(); std::vector<tipi::operazione>::iterator op = op_.begin(); std::vector<tipi::prezzo>::iterator finePr = prezzo_.end(); std::vector<tipi::operazione>::iterator fineOp = op_.end();
while( op!=finePr && pr!=fineOp ) {
I think what you mean is:
while( op!=fineOp && pr!=finePr ) {
In article <oU*******************@tornado.fastwebnet.it>, "Giulio"
<giulio.gL E V A@email.it> says... I'm doing a class who takes in constructor a vector<int> keeps and makes some statistic on the vector whitout modifiing it.
I would not pass the vector itself at all. Instead, I'd consider
passing a pair of iterators, one to the beginning and the other to the
end of the vector.
--
Later,
Jerry.
The universe is a figment of its own imagination.
> Instead, I'd consider passing a pair of iterators, one to the beginning and the other to the end of the vector.
wow this is a great idea...
thanx to all for the good answers
Giulio This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alex Vinokur |
last post by:
Various forms of argument passing
=================================
C/C++ Performance Tests
=======================
Using C/C++ Program Perfometer...
|
by: {AGUT2} {H}-IWIK |
last post by:
Hi,
I'm trying to pass my vector to a function external to my main(), but my
compiler is complaining. FYI, the struct for the facetInfo works perfectly,
it's just the vector passing.
A quick...
|
by: news.tiscali.dk |
last post by:
This might be a really simple question, but here goes: How can I pass an
array to a function and have the function put values into that array? Some
code to clearify (mat is a matrix class)
float...
|
by: justanotherguy63 |
last post by:
Hi,
I am designing an application where to preserve the hierachy and for
code substitability, I need to pass an array of derived class object in
place of an array of base class object. Since I...
|
by: lugal |
last post by:
This might be more appropriate here. I'm new to C++, coming from a
background in another languages that allowed a similar solution to work
(Python). I wrote the following code in C++ based on the...
|
by: Michael |
last post by:
Hi,
once I read here that it is not 'a good idea'
to pass variables that are not initialized to
a function.
I have
void something ( double *vector );
....
|
by: gouse |
last post by:
Hi, Friends
I have a table with 2 lakh records (one text field, one int4 field, and a Gemetry field). When I was executing the query using Binary cursors, It was taking nearly 35 seconds. I am...
|
by: pereges |
last post by:
which one do you think is better ? I need to make my program efficient
and in some places I have passed the copy of a variable which makes
life some what easy while writing huge expressions but...
|
by: Giovanni Gherdovich |
last post by:
Hello,
I'm doing some toy experiments to see how
the algoritm std::transform and the function
adapter std::bind2nd can play together, but
my compiler give my the error
error: passing `const...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |