Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Vector<Vector<double>> (Error in creating Vector<Vector<double>>)
Vector<Vector<double>> [message #49513] Thu, 22 February 2018 05:45 Go to next message
Upp_User is currently offline  Upp_User
Messages: 8
Registered: May 2017
Location: India
Promising Member
Hello,
I wanted to create a square matrix using Vector<vector<double>>, However i am getting a error message during compilation.

I am using
Windows 10, Mingwx64,U++ 10804.

When i use 1D Vector (Vectors are 1D indeed Razz) i am getting the dynamic array initialization without any problem, but if i try 2D Array it seems not working.

Can i get some Help please!!!

Below is the code and the error message.

#include <Core/Core.h>
#include <iostream>
using namespace Upp;
using namespace std;

class Bezier
{
	public:
	Vector<Vector<double>> bezy;
	void getBez();
	void showBez();
};

CONSOLE_APP_MAIN
{
	Bezier myBez;
	myBez.getBez();
	myBez.showBez();
}

void Bezier::getBez()
{
	cout<<"generating the square matrix"<<endl;
	
	for(int i=0;i<5;i++)
	{
		for(int i=0;i<5;i++)
		{
			bezy.Add()=i;
		}
	}

	
}

void Bezier::showBez()
{
	StdLogSetup(LOG_COUT|LOG_FILE);
	cout<<"Display Square matrix"<<endl;
	DUMP(bezy);
}


Error Message during compiling:

D:\Migration\Myself\others\programming\upp\MyApps\Vector_2d\ Vector_2d.cpp (29): error: no match for 'operator=' (operand types are 'Upp::Vector<double>' and 'int')
(): bezy.Add()=i;
(): In file included from D:\Migration\Myself\others\programming\upp/uppsrc/Core/Core. h:269:0,
(): from D:\Migration\Myself\others\programming\upp\MyApps\Vector_2d\ Vector_2d.cpp:1:
D:\Migration\Myself\others\programming\upp/uppsrc/Core/Vcont .h (181): note: candidate: void Upp::Vector<T>::operator=(Upp::Vector<T>&&) [with T = double]
(): void operator=(Vector&& v) { if(this != &v) { Free(); Pick(pick(v)); } }
D:\Migration\Myself\others\programming\upp/uppsrc/Core/Vcont .h (181): note: no known conversion for argument 1 from 'int' to 'Upp::Vector<double>&&'



UPP User
Re: Vector<Vector<double>> [message #49514 is a reply to message #49513] Thu, 22 February 2018 07:00 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1371
Registered: December 2006
Ultimate Contributor
bezy.Add() returns Vector<double>&
So, you are basically trying to assign integer to Vector<double>.


Regards,
Novo
Re: Vector<Vector<double>> [message #49517 is a reply to message #49514] Thu, 22 February 2018 08:22 Go to previous messageGo to next message
Upp_User is currently offline  Upp_User
Messages: 8
Registered: May 2017
Location: India
Promising Member
Thanks for the clarification. i modified as below and it worked as expected.
void Bezier::getBez()
{
	cout<<"generating the square matrix"<<endl;
	
	for(int i=0;i<5;i++)
	{
		for(int i=0;i<5;i++)
		{
			tbez.Add()=double(i);
		}
		bezy<<tbez;
		tbez.Clear();
	}

	
}


But is there an easy way to directly assign the values. like, bezy[i][i]=double(i)?, using it, is not giving any compilation error, but shows assertion failed.

Thanks


UPP User
Re: Vector<Vector<double>> [message #49519 is a reply to message #49517] Thu, 22 February 2018 10:40 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 273
Registered: March 2010
Experienced Member
bezy.Add().Add()=i;

or
bezy.Add().Add(i);


regards
omari.
Re: Vector<Vector<double>> [message #49520 is a reply to message #49519] Thu, 22 February 2018 10:51 Go to previous message
Upp_User is currently offline  Upp_User
Messages: 8
Registered: May 2017
Location: India
Promising Member
Thanks a lot.
Exactly what i was looking for.


UPP User
Previous Topic: Problem with websocket connect method
Next Topic: How to close the websocket connection
Goto Forum:
  


Current Time: Fri Nov 01 00:02:58 CET 2024

Total time taken to generate the page: 0.01707 seconds