Hi,
Is it possible to insert a class <vec> which has a vector<double>
member, into the vector<vec> veclist for e.g?
I've been getting compilation errors when trying to insert using the
vector method push_back() ->
c:\program files\microsoft visual studio\vc98\inc lude\xutility(3 9) :
error C2679: binary '=' : no operator defined which takes a right-hand
operand of type 'const class vec' (or there is no acceptable
conversion)
c:\program files\microsoft visual studio\vc98\inc lude\vector(170 ) : see
reference to function template instantiation 'void __cdecl
std::fill(class vec *,class vec *,const class vec &)' being compiled
c:\program files\microsoft visual studio\vc98\inc lude\xmemory(34 ) :
error C2558: class 'vec' : no copy constructor available
c:\program files\microsoft visual studio\vc98\inc lude\xmemory(66 ) : see
reference to function template instantiation 'void __cdecl
std::_Construct (class vec *,const class vec &)' being compiled
Error executing cl.exe.
I've already had an overloaded operator= for my vec class and i dont
really understand where the error lies in.
Here is my source code:
class <vec> header file
public:
vec();
vec(vec&);
vec(int, int); //dimension, vecid
vec(int, int, vector<double>) ; //dimension, vecid, coords
vec(int, int, vector<double>, vector<int>); //dimension, vecid,
coords, list of conected vecs
~vec();
void setvecid(int);
void setveccoord(vec tor<double>);
void setvecconnect(v ector<int>);
void setvec(int, int, vector<double>, vector<int>);
void setvec(vec&);
int getdim();
int getvecid();
vector<double> getcoord(); //get the point coordinates
vector<int> getvecconnect() ; //get the list of connected vecs
void addconnectvec(i nt); //add connected vec to the vecconnect list
void delconnectvec(i nt); //remove connected vec from list
bool searchvec(int); //search for vec in the vecconnect list
void sortvecconnect( ); //sort the list in the
vec operator=(vec&) ;
In my main(), i declare a global variable:
vector<vec> globalvecs;
I get the compile error when i use the statement:
globalvecs.push _back(tmpvec);
inside the following block of code:
for(i = 0; i < numVec; i++)
{
vec tmpvec(dimensio n, i); //temp vec used to add to the global veclist
vector<double> tmpcoord; //vector to hold temp coordinates b4 setting
//tmpvec's coord
for(j = 0; j < dimension; j++)
{
read >> x; //where x is of type double
tmpcoord.push_b ack(x);
}
tmpvec.setvecco ord(tmpcoord);
globalvecs.push _back(tmpvec);
}
Advance thanks for your replies!
Regards,
sw
Jul 23 '05
11 6305
I omitted the copy constructor accidentally. Here it is now:
vec::vec(const vec &newvec)
{
dim = newvec.dim;
vecid = newvec.vecid;
setveccoord(coo rd);
setvecconnect(v ecconnect);
}
sw wrote: I omitted the copy constructor accidentally. Here it is now:
vec::vec(const vec &newvec) { dim = newvec.dim; vecid = newvec.vecid; setveccoord(coo rd); setvecconnect(v ecconnect); }
Here we go. You probably meant:
setveccoord(new vec.coord);
setvecconnect(n ewvec.vecconnec t);
Generally, you should prefer initialization over assignment in constructors.
vec::vec(const vec &newvec)
: dim(newvec.dim) ,
vecid(newvec.ve cid),
coord(newvec.co ord),
vecconnect(newv ec.vecconnect)
{
}
Btw: Is that really all that your copy constructor is doing? If yes, you
should just remove it alltogether. If you don't define your own, the
compiler automatically generates one that does a memberwise copy, which is
what yours also does. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: k0tic |
last post by:
The intent of the following code is to call delete on each pointer in
the vector dead implicitly via auto_ptr<T>'s reset method semantics
which
delete their current pointer before taking ownership of reset's arg
in addition to when the object is destroyed -- in this case when,
as an automatic functor variable, the auto_ptr goes out of scope.
Is the following code legal and if not, why not.
Thanks in advance,
-L
|
by: William Payne |
last post by:
Consider this (templated) class member function:
template<typename Type>
void CircularContainer<Type>::insert(const Type& s)
{
vector<Type>::iterator itr = find(m_elements.begin(), m_elements.end(),
s);
// snip
}
|
by: Honestmath |
last post by:
Hi,
I added the following line to my code within a class declaration:
std::vector<Date> m_duedates(100);
I also tried:
std::vector<Date> m_duedates(100, Date());
|
by: George Economos |
last post by:
Hi all,
I am using msvc 7.1 and have encountered the following code:
-----------
A.hpp
-----------
class A
{
|
by: Christian Chrismann |
last post by:
Hi,
I've a runtime problem with STL vectors.
Here is the simplified version of the code:
template <class Tclass A {
...
private:
vector<T*myvector;
typename vector<T*>::itarator mIt;
| |
by: Nelis Franken |
last post by:
Good day.
I'm having trouble telling STL to use a member function to sort items
within the relevant class. The isLess() function needs to have access
to the private members of the Foo class to determine if the one item is
less than the other (it uses two vectors, one containing the actual
data, and one that stores IDs that index into the data vector). The
code below is pretty self-explanatory. I've looked into mem_fun, but
I'm stuck....
|
by: Jess |
last post by:
Hello,
I have a program that stores dynamically created objects into a
vector.
#include<iostream>
#include<vector>
using namespace std;
|
by: jubelbrus |
last post by:
Hi
I'm trying to do the following.
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
class {
|
by: Saltydog |
last post by:
Ok so I ahve spent a while reading around this site and some others, and I thought there might of been some errors with my includes, but now I am just really confused. Basically I have a 3 classes, a main class and 2 sub classes the sub classes point at each other, but interactions is no more then pointing.
In the main program I have #include "school.h" in the header. I have the error
from schoolMain.cpp In file included from school.h:5,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |