Archived

This topic is now archived and is closed to further replies.

What is wrong with this code? (vectors)

This topic is 6362 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to make vectors work with classes a long time now but I can''t make it work. Here''s the code (test application):
    #include <iostream.h>
#include <windows.h>
#include <vector>

using namespace std;

class Fff
{
public:
	int y;
	int z;
};

class space
{
public:
	vector< Fff > varden;
	space(void)
	{
		varden.resize(1);

	}
};

//vector< Fff * > space::varden(0);

//vector < fffff > space::varden(0);


void main ()
{	
	space sp;
	Fff fg;

	//sp.varden[0] = fg;


	int g;
	cin>>g;
}    
This code gives me these errors: C:\Program Files\DevStudio\MyProjects\vectors\test.cpp(40) : warning C4101: ''fg'' : unreferenced local variable C:\Program Files\DevStudio\VC\INCLUDE\xutility(45) : error C2784: ''bool __cdecl std::operator <(const class std::reverse_iterator<`template-parameter-1'',`template-parameter-2'',`template-parameter-3'',`template-parameter-4'',`template-parameter-5''> &,c onst class std::reverse_iterator<`template-parameter-1'',`template-parameter-2'',`template-parameter-3'',`template-parameter-4'',`template-parameter-5''> &)'' : could not deduce template argument for ''const class std::reverse_iterator<`template-parameter- 1'',`template-parameter-2'',`template-parameter-3'',`template-parameter-4'',`template-parameter-5''> &'' from ''const class Fff'' C:\Program Files\DevStudio\VC\INCLUDE\xutility(45) : error C2784: ''bool __cdecl std::operator <(const struct std::pair<`template-parameter-1'',`template-parameter-2''> &,const struct std::pair<`template-parameter-1'',`template-parameter-2''> &)'' : could not deduce template argument for ''const struct std::pair<`template-parameter-1'',`template-parameter-2''> &'' from ''const class Fff'' C:\Program Files\DevStudio\VC\INCLUDE\xutility(45) : error C2676: binary ''<'' : ''const class Fff'' does not define this operator or a conversion to a type acceptable to the predefined operator C:\Program Files\DevStudio\VC\INCLUDE\xutility(47) : error C2784: ''bool __cdecl std::operator <(const class std::reverse_iterator<`template-parameter-1'',`template-parameter-2'',`template-parameter-3'',`template-parameter-4'',`template-parameter-5''> &,c onst class std::reverse_iterator<`template-parameter-1'',`template-parameter-2'',`template-parameter-3'',`template-parameter-4'',`template-parameter-5''> &)'' : could not deduce template argument for ''const class std::reverse_iterator<`template-parameter- 1'',`template-parameter-2'',`template-parameter-3'',`template-parameter-4'',`template-parameter-5''> &'' from ''const class Fff'' C:\Program Files\DevStudio\VC\INCLUDE\xutility(47) : error C2784: ''bool __cdecl std::operator <(const struct std::pair<`template-parameter-1'',`template-parameter-2''> &,const struct std::pair<`template-parameter-1'',`template-parameter-2''> &)'' : could not deduce template argument for ''const struct std::pair<`template-parameter-1'',`template-parameter-2''> &'' from ''const class Fff'' C:\Program Files\DevStudio\VC\INCLUDE\xutility(47) : error C2676: binary ''<'' : ''const class Fff'' does not define this operator or a conversion to a type acceptable to the predefined operator Error executing cl.exe. test.obj - 6 error(s), 1 warning(s)

Share this post


Link to post
Share on other sites
A quick glance at your code:

most of the stl container templates require that you have a copy constructor, an assignment operator. I am not sure, but if you use the find template , not using a pred, you will need to have the comparison operators defined as well. ==, !=, these 2 at least.

Try adding a copy constructor and an assignment operator overload. See what happens then.

Alek

Share this post


Link to post
Share on other sites
Hmmm... This code compiles fine for me using VC 6.0 SP 3, so I don''t think it''s your code that''s the problem. It''s either a bug in your version of VC or a busted VC install. I''d recommend just trying some very simple code to see if ANY stl stuff works. Eg:

void main ()
{
vector v;
v.push_back(1);
}

You could also try installing the newest SP for VC, or porting the SGI implementaion of stl (http://www.sgi.com/Technology/STL/download.html).

...Syzygy

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well VC5 is not your problem, I just copy & pasted the code into VC5 and it compiled fine (other than that warning about not referencing a local variable, but thats not important in this case). As was pointed out above, you probably have a broken install. Try reinstalling VC5, and getting Service Pack 3 for DevStudio (can be found on Microsoft''s web site), and while your at it, go ahead and download the newest Platform SDK for Windows.

Share this post


Link to post
Share on other sites