|
VeganFanatic wrote: assert(this->data[].size() == this->data.size()); // Must be a square
what is data type of data!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I make everything a template. This way its agnostic to the underlying data to a point.
I have templates for vector and matrix already and I can now use vector equations, so when I made my matrix I leveraged that capability a lot. Make the work a lot easier.
I finally have LU decomposition, I wanted other algorithms in the library to be used in special cases.
http://www.contract-developer.tk
|
|
|
|
|
Hello everybody!
I create the class used to show some graphics, like this:
CMyElemView >> CZoomView >> CScrollView >> CView
when I called this,but is empty .
void CMyElemView ::PrintPreview()
{
CScrollView::OnFilePrintPreview();
}
void CMyElemView ::Print()
{
CScrollView::OnFilePrint();
}
otherwise , I created other class,it used to show some text:
CMyTextView >> CTextBaseView >> CBCGPEditView >> CView
This can be successed to show the text, but the CMyElementView doesn't.
What cause is this error generally ?
|
|
|
|
|
I have created a class and a tamplate to create an array with a size based on two of the parameters. What I am looking to do is populate the years[0] with the start parameters value and continue to year[stop]= the stop parameters value.
#include<iostream><br />
using namespace std;<br />
<br />
template <class T, int start, int stop><br />
class MyArray {<br />
T test [stop-start]; <br />
};<br />
<br />
int main () {<br />
MyArray <int, 1790, 1820> years; <br />
return 0;<br />
}<br />
so... MyArray <int, 1790, 1820> years; would create an array with 30 values starting at array[0] = 1790 and ending with array[30]=1820. Is this possible?
|
|
|
|
|
To begin with, I think you want stop-start+1 because 1790 to 1820 is actually 31 years. Correspondingly, if you passed in 1 and 10 you should have 10 items and not 9, right ?
Anyway, no, I don't think you can do exactly what you wrote there. Have you seen what the compiler thinks about that ? It will probably tell you that the array size must be a constant expression. I think you need to use new to make the array of variable size.
|
|
|
|
|
As long as the start and stop values are compile-time constants, I am pretty sure you can use Template Metaprogramming[^] to populate the array.
|
|
|
|
|
I recommend you use the std::vector class for this.
You can do the following -
std::vector<T> myArray;
myArray.reserve(stop - start + 1);
|
|
|
|
|
I think you meant vector::resize() .
---
IMO using the std::vector does not add any value in this case. In fact it's the other way around.
* It will allocate memory from the heap, whether you have an automatic instance or not. Possibly affecting performance and fragmentation. (Not a problem for most application, but still)
* There is no added bounds checking. It is just as good (or bad) as the native array.
* Memory management is provided for you in both cases.
Use of std::vector might be useful if:
* You work with years spanning over millions of years. Otherwise it might consume your stack in no-time.
* Maybe the compiler/linker can optimize your class due to the fact that all instances (with the same type parameter) have the same size. (sizeof(std::vector<int>) is not affected by the number of elements while sizeof(int[N]) is.) Unfortunately, my knowledge of linker optimization techniques is not what it should be so I really don't know. But I wouldn't mind knowing.
|
|
|
|
|
template <class T, int start, int stop>
class MyArray {
T test [stop-start+1];
public:
MyArray()
{
for (int i = 0; i < (stop - start + 1); ++i)
test[i] = start + i;
}
};
MyArray<int, 1999, 2010> arr;
|
|
|
|
|
Here's a quick counter question... Do you actually need an array?
The reason this springs to mind is that you've made the array private so no one outside of your interface can use it. Well, apart from using some disgusting tricks that you should burn in a personal hell for.
So if your final class interface is going to be something like:
template <class T, int first, int last>
class year_range
{
public:
T nth_year_in_range( int n );
};
you could actually eliminate the array wholesale:
T nth_year_in_range( int n )
{
return T( start + n );
}
Of course if you need the array for something else then this won't work.
Cheers,
Ash
|
|
|
|
|
matrix operator=(const matrix &that) {
matrix ret;
ret.resize(this->data.size(), this->data[0].size());
for (int i = 0; i < that.data.size(); i++)
for (int j; j > that.data[0].size(); j++)
ret[i][j] = that[i][j];
return ret;
};
Seems to be no good, what am I doing wrong
http://www.contract-developer.tk
|
|
|
|
|
are you getting an error message of any kind ?
|
|
|
|
|
Claims there are no operators available, to support the abstract vector algebra.
Error 2 error C2679: binary '-' : no operator found which takes a right-hand operand of type 'aa::vector<base>' (or there is no acceptable conversion) matrix.h 114 1 fibonacci
http://www.contract-developer.tk
|
|
|
|
|
vector operator-(const vector *that) { // parallelogram law
vector ret;
assert(this->data.size() == that.data.size());
ret.resize(this->data.size());
#pragma omp parallel for
for (int i = 0; i < this->data.size(); i++)
ret.data[i] = this->data[i] - that.data[i];
return ret;
};
http://www.contract-developer.tk
|
|
|
|
|
Without knowing what your representation of matrix is it's a bit hard to work out if you're copying it correctly.
Cheers,
Ash
PS: Having said that what you've implemented is going to be more of a factory or clone method. While it might be legal C++ it wouldn't half surprise anyone trying to use the class. Would you expect that writing a = b; wouldn't change the value of a?
|
|
|
|
|
Should be:
matrix operator=(const matrix &that) {
for (int i = 0; i < this->rows; i++)
for (int j=0; j < this->cols; j++)
(*this)[i][j] = that[i][j];
return *this;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am trying to load a picture from memory
from inspection can you see why this dosen't work?
here is part of the class I am using:
BOOL CPicture::Load(IStream* pstm)
{
Free();
HRESULT hr = OleLoadPicture(pstm, 0, FALSE,
IID_IPicture, (void**)&m_spIPicture);
return hr == S_OK;
}
here is some code I have found to implement this:
ifstream file ("c:\\1.jpg", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
IStream *pStrm = NULL;
HGLOBAL hgbl = GlobalAlloc (0, 852);
CreateStreamOnHGlobal (hgbl, true, &pStrm);
pStrm->Write(memblock, size, 0);
delete [] memblock;
m_pict.Load(pStrm);
}
Thabk you your help will be much appreciated Simon
|
|
|
|
|
simon alec smith wrote: from inspection can you see why this dosen't work?
Not really, unless you explain what you mean by "doesn't work"; such a statement does not help in understanding what your problem is. Does your program crash, throw an exception, paint the image upside down, etc.?
It's time for a new signature.
|
|
|
|
|
This is what was reported,
File c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h
line 622
expression: p!= 0
|
|
|
|
|
simon alec smith wrote: expression: p!= 0
And how does this relate to your code, where does the stack history point to in your program?
It's time for a new signature.
|
|
|
|
|
This does not work as expected, for matrix * matrix
matrix operator*(const matrix that) { // matrix product AB != BA
matrix ret;
ret.resize(this->data.size(), that.data.size());
for (int i = 0; i < this->data.size(); i++) {
for (int j = 0; j < this.data[i].size(); j++) {
for (int k = 0; k < this->data.size(); k++) {
#pragma omp parallel for
for (int l = 0; l < this.data[i].size(); l++) {
ret[i][k] += this->data[i][k] * that.data[j][k];
}
}
}
}
return ret;
http://www.contract-developer.tk
|
|
|
|
|
So what exactly is the question? Have you used the debugger to step through the code? Have you removed the #pragma directive? Have you worked out on paper how to do the multiplication?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
The result from a test != book
http://www.contract-developer.tk
|
|
|
|
|
VeganFanatic wrote: for (int i = 0; i < this->data.size(); i++) {
for (int j = 0; j < this.data[i].size(); j++) {
for (int k = 0; k < this->data.size(); k++) {
#pragma omp parallel for
for (int l = 0; l < this.data[i].size(); l++) {
ret[i][k] += this->data[i][k] * that.data[j][k];
}
}
}
}
AFAIK it should be
for (int i = 0; i < this->rows; i++)
for (int j = 0; j < that->cols; j++)
{
ret[i][j] = .0;
for (int k = 0; k < this->cols; k++)
ret[i][j] += this->data[i][k] * that.data[k][j];
}
Why do you need the further loop?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I need to parse a .dat file which contains hexadecimal data. I need to parse the contents and store it as a text file.
I have the .dat file and the header file. Can anyone tell me how should I start with it or what are the steps involved.
|
|
|
|