|
I think that you'll find that strides are more applicable to multi-dimensional arrays - for a contiguous slice of a 1-D array, the stride will be 1.
I would suggest that if you want 1-D arrays only and you're manipulating contiguous sub-sets of the array, then use vector. valarray has been generally recognised as not the best solution for the problem it was designed to solve (see this[^] and this[^]).
<edit>
And here's an example of valarray :
#include <valarray>
#include <iostream>
#include <iterator>
int main(int, char**)
{
std::valarray<int> v(10);
for(int i=0;i<v.size();++i)
v[i] = i;
std::valarray<int> v2(10);
for(i=0;i<v2.size();++i)
v2[i] = 200;
for(i=0;i<v.size();++i)
std::cout << ((i==0)?"":", ") << v[i];
std::cout << "\n";
std::slice_array<int> s = v[std::slice(1, 3, 2)];
s += v2;
for(i=0;i<v.size();++i)
std::cout << ((i==0)?"":", ") << v[i];
std::cout << "\n";
return 1;
}
gives this output
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
0, 201, 2, 203, 4, 205, 6, 7, 8, 9
std::slice(1, 3, 2) defines a subset of a valarray containing 3 elements, starting at element 1 of the valarray, with each element of the slice separated by one valarray element (i.e. the slice references elements 1, 3 and 5 of the valarray ).
But I'd still use a vector - valarray doesn't have iterators and isn't a proper STL container.
</edit>
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Thanks, that was most helpful! And those articles made for some interesting reading...
As you say, a vector would be a better solution, in almost every way. I was only thinking about valarray because it looked like it could be useful. After reading those articles though, I think I'm going to "forget" that valarray even exists!
|
|
|
|
|
Hi friends
I would like to know if there is any difference between
the files, say test.dll and test.ocx ,if I simply change the output filename?.(Provided the same code is used for both files)
-friendly Dracula
|
|
|
|
|
|
Thank you Michael Dunn for ur reply.
-Friendly Dracula
|
|
|
|
|
I've been trying to use WTL controls in my large MFC based project. I've got the WTL7 libraries installed on my VC6 system. I can compile the WTL ctrl's sample code just fine, but when I try using it with MFC code, I'm getting all sorts of namespace collisions. CEdit, CButton, etc.
Can WTL and MFC code be intermingled? Does anyone have an example of how to do this? I'm guessing careful use of "using ... { ... }" is the key, or being more explicit with class names.
|
|
|
|
|
aha, CodeProject to the rescue.
http://www.codeproject.com/wtl/mix_wtl_mfc.asp
Apparently there are some #define's you can set to cause WTL to not define symbols that will clash with MFC (which puts everything in the global namespace)
|
|
|
|
|
Please not that is for VC6/ATL3. It may not work with your development environment if it's VS.NET/ATL7.
Come to think of it, there is some wizard in VS.NET that allows "adding ATL support to MFC projects". Please try that before trying my previous response.
And the #define stuff mentioned in the article too.
--
He just smiled and gave me a vegemite sandwich.
|
|
|
|
|
WTL7.1 in an ATL7 environment (VS.NET and later) will assume there is a global variable called _AtlBaseModule .
I can't remember all functions it must have, but you'll figure it out as you see the compilation errors. I know it needs a function called GetResourceHandle() . It should just return the HINSTANCE for your resources.
I would suggest that you do something like this in your stdafx.h:
#include "youratlbasemodule.h"
extern YourAtlBaseModuleEmulator _AtlBaseModule;
#include <atlapp.h>
#include <atlctrls.h>
...
And then in your youratlbasemodule.h:
class class YourAtlBaseModuleEmulator {
HINSTANCE m_hInstance;
public:
void SetResourceInstance(HINSTANCE hInstance) { m_hInstance = hInstance; }
HINSTANCE GetResourceInstance() { return m_hInstance; }
};
And then in your "main" cpp file:
#include "youratlbasemodule.h"
...
YourAtlBaseModuleEmulator _AtlBaseModule;
...
_AtlBaseModule.SetResourceInstance(hInstance);
I think something along those lines should work. I have never done it before.
--
He just smiled and gave me a vegemite sandwich.
|
|
|
|
|
Thanks for the explicit examples!
There are so many hot (trendy?) WTL controls out there that I'd love to use in my apps, but getting the code to compile together has always been a bottle neck.
|
|
|
|
|
I want to harness the power of STL in my code. But I am not able to become comfortable with STL. May be because of my inexperience.
Presently I am working with string . What I want to pass from a dll a function which will accept List of employees and Number of employees and I will save it in a class member variable. How to do it is the question?
|
|
|
|
|
Hello everyone:
Could you teach me how to read file line by line?
If having some samples, please send to me by email.
Thank you.
-Freehawk.
|
|
|
|
|
freehawk wrote:
Could you teach me how to read file line by line?
Look up getline.
freehawk wrote:
If having some samples, please send to me by email.
No. If you won't look here again for your answer, especially when the site sends you an email to say you've been replied to, why should we send you an email and risk ending up on a spam list somewhere ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Thank you for the reply.
where is the "getline"? Could I use it in a wtl7.1 project?
-Freehawk
|
|
|
|
|
the beauty of solutions like using getline are that they are part of C++, not part of any framework. Therefore you can use them in any C++ project. I *think* getline lives in iostream ( NOT iostream.h ). ifstream lives in fstream.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Here is the solution using std::getline().
std::string sInput;
std::getline(inputStream, sInput);
Kuphryn
|
|
|
|
|
Thank you very much.
It is just what I need.
I will try it.
-Freehawk
|
|
|
|
|
Hello everyone:
Example I receive some messages and want to do somethings same with clicking the button of toolbar, how to realize?
and how to disble/enable the buttons of toolbar?
Thank you.
-Freehawk.
|
|
|
|
|
|
Thank you very much.
I will try it.
-Freehawk
|
|
|
|
|
Hello everyone:
I want to transfer a function pointer from a WTL project to a MFC dll.
Do I need to make the function as a CALLBACK function?
How to transfer it?
-Freehawk
|
|
|
|
|
Through a function call perhaps? How would you do it otherwise?
Just define the function pointer type in a header file which the MFC dll and WTL project has access to during compile time. And add a function in the MFC dll which can deliver the function pointer.
I.e.:
typedef void (*FuncPtr)(type, type2, type3);
void InstallFunctionCallback(FuncPtr fptr);
And implement InstallFunctionCallback accordingly in your MFC dll.
--
Try walking in my shoes. You stumble in my footsteps.
|
|
|
|
|
Thank you for the reply.
I finished it, but I have not made the function as a callback function.
could you tell me what difference is between a function and a callback function translated
to dll as a function pointer?
-Freehawk
|
|
|
|
|
freehawk wrote:
tell me what difference is between a function and a callback function translated
to dll as a function pointer?
There is no difference really. Callback is just a semantic label for programmers.
--
Try walking in my shoes. You stumble in my footsteps.
|
|
|
|
|
Thank you for the reply.
I did it.
-Freehawk
|
|
|
|