 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Michael Guest
|
Posted: Sun Dec 24, 2006 10:10 am Post subject: Vector and classes |
|
|
Hi,
I am new to C++ and have run into the following problem. I have written
some functions which return a vector e.g
vector<double> myfunction(double arg1,.......,.....)
{
}
I woud like to create a class out of this functions, however I dont
know how to write the header file correctly, when i use:
#ifndef MYCLASS_H
#define MYCLASS_H
vector<double> myfunction(double arg1,.......,.....);
#endif
I get the error the vector is not template. Would be great if somebody
could help.
Happy x-mas to everyone
Michael |
|
| Back to top |
|
 |
Mirek Fidler Guest
|
Posted: Sun Dec 24, 2006 10:10 am Post subject: Re: Vector and classes |
|
|
Michael wrote:
| Quote: | Hi,
I am new to C++ and have run into the following problem. I have written
some functions which return a vector e.g
vector<double> myfunction(double arg1,.......,.....)
{
}
I woud like to create a class out of this functions, however I dont
know how to write the header file correctly, when i use:
#ifndef MYCLASS_H
#define MYCLASS_H
vector<double> myfunction(double arg1,.......,.....);
|
std::vector<double> myfunction(double arg1,.......,.....);
Also note that this is quite fragile performance-wise, if RVO is not
used to optimize out the copy of vector (-> because of inferior
compiler or specific situation). Perhaps the better solution here is
myfunction(std::vector<double>& , ....); |
|
| Back to top |
|
 |
Gianni Mariani Guest
|
Posted: Sun Dec 24, 2006 10:10 am Post subject: Re: Vector and classes |
|
|
Michael wrote:
| Quote: | Hi,
I am new to C++ and have run into the following problem. I have written
some functions which return a vector e.g
vector<double> myfunction(double arg1,.......,.....)
{
}
I woud like to create a class out of this functions, however I dont
know how to write the header file correctly, when i use:
#ifndef MYCLASS_H
#define MYCLASS_H
|
#include <vector>
| Quote: |
vector<double> myfunction(double arg1,.......,.....);
|
std::vector<double> myfunction(double arg1,.......,.....);
| Quote: |
#endif
I get the error the vector is not template. Would be great if somebody
could help.
|
Firstly you need to include <vector> and second you need to specify
which namespace. Since you're using it in a header, you should not do a
"using namespace std". My preference is to fully quality the namespace
on each use in the header. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|