|
|
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 |
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 ) 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 #49517 is a reply to message #49514] |
Thu, 22 February 2018 08:22 |
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
|
|
|
|
|
Goto Forum:
Current Time: Fri Nov 01 00:02:58 CET 2024
Total time taken to generate the page: 0.01707 seconds
|
|
|