C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Vector and classes

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Michael
Guest





PostPosted: Sun Dec 24, 2006 10:10 am    Post subject: Vector and classes Reply with 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,.......,.....);

#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





PostPosted: Sun Dec 24, 2006 10:10 am    Post subject: Re: Vector and classes Reply with quote



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





PostPosted: Sun Dec 24, 2006 10:10 am    Post subject: Re: Vector and classes Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.