|
I want to write a C++ template class Nvector that enables arrays with negative subscripts to be defined. The class should be usable in the following code fragment:
>
> Nvector<double> a; // instantiate double array class
> a.resize(-10, 10); // allocate array from locations -10 to 10
> for(int i=-10 ; i<=10 ; ++i)
> a[i] = exp(-k*(T-k*i)); // fill array
>
Also, the class should be written so that array set/access is optimally efficient. Show through the template specification that multidimensional arrays can also be defined.
I coded up like this:
// array template
#include <iostream.h>
#include "Nvector.h"
#include "math.h"
int main()
{
int k = 3;
NvectorDouble<double> a[21];
a.resize(-10, 10);
for (int i =-1; i<= 10; i++)
a[i] = exp( -k*(10-k*i) );
return 0;
}
// the template class included in the head file Nvector.h
#include <iostream.h>
template <class t="">
class NvectorDouble
{
int lowIndex, highIndex; // the low and high index allowed
double *data; // pointer to the vectored data
public:
NvectorDouble (); // default constructor
~NvectorDouble (); // class destructor
bool resize(int newLowIndex, int newHighIndex); // allocates memory for data
double &operator[] (int index); // overload the [] operator
};
template<class t="">
bool NvectorDouble<t>::resize(int newLowIndex, int newHighIndex){
lowIndex = newLowIndex;
highIndex = newHighIndex;
double data[highIndex-lowIndex];
}
But I couldn't get it to run correctly, please be aware that I am a beginer in C++, could you please help me this?
|
|
|
|
|
What error are you getting? Compile time or run time? Also, make sure you check the "Do not treat <'s as HTML tags" checkbox before posting template code.
Regards
Senthil
_____________________________
<font face="Verdana" size=1><a href="http://blogs.wdevs.com/senthilkumar">My Blog</a> | <a href = "http://www.codeproject.com/script/articles/list_articles.asp?userid=492196">My Articles</a> | <a href = "http://geocities.com/win_macro">WinMacro</a></font>
|
|
|
|
|
Dear Senthil,
Thanks for your reply.
Post again !!
I have problem with the operator overloading i think.
I want to write a C++ template class Nvector that enables arrays with negative subscripts to be defined. The class should be usable in the following code fragment:
>
> Nvector a; // instantiate double array class
> a.resize(-10, 10); // allocate array from locations -10 to 10
> for(int i=-10 ; i<=10 ; ++i)
> a[i] = exp(-k*(T-k*i)); // fill array
>
Also, the class should be written so that array set/access is optimally efficient. Show through the template specification that multidimensional arrays can also be defined.
I coded up like this:
// array template
#include
#include "Nvector.h"
#include "math.h"
int main()
{
int k = 3;
NvectorDouble a[21];
a.resize(-10, 10);
for (int i =-1; i<= 10; i++)
a[i] = exp( -k*(10-k*i) );
return 0;
}
// the template class included in the head file Nvector.h
#include
template
class NvectorDouble
{
int lowIndex, highIndex; // the low and high index allowed
double *data; // pointer to the vectored data
public:
NvectorDouble (); // default constructor
~NvectorDouble (); // class destructor
bool resize(int newLowIndex, int newHighIndex); // allocates memory for data
double &operator[] (int index); // overload the [] operator
};
template
bool NvectorDouble::resize(int newLowIndex, int newHighIndex){
lowIndex = newLowIndex;
highIndex = newHighIndex;
double data[highIndex-lowIndex];
}
But I couldn't get it to run correctly, please be aware that I am a beginer in C++, could you please help me this?
|
|
|
|
|
No one can/will help if you do not post the exact error.
John
|
|
|
|
|
Could you please run it on your system? I dont know what's the exact problem.
Many thanks.
|
|
|
|
|
Ok, I guess the problem is a logic error. Possibly later I will do that I am currently running linux and I do not want to wait the 5 minutes it takes to reboot my pc.
John
|
|
|
|
|
Thanks a lot, John, I appreciate very much for your help indeed!!
John
|
|
|
|
|
I do not have a solution but I have a suggestion. Use a vector as a class member to actualy hold the data (a lot of work went into make it efficient).
template<clas T>
class my_class
{
public:
typedef std::vector<T> array_type;
void resize(int d1,int d2)
{
unsigned new_size = abs(d1) + abs(d1);
if( !(new_size & 1) )
++new_size;
data_array.resize(new_size);
center_index = new_size>>1;
}
const T& get_at(int index)
{
unsigned new_index = center_index + index;
if( new_index >= data_array.size() )
throw(range_error );
data_array[new_index];
}
protected:
array_type data_array;
unsigned center_index.
};
The above has a long way to go before it meets your requirements, but it is a good place to begin.
Oh; by the way, the following will not work and will generate errors:
lowIndex = newLowIndex; // not know at runtime
highIndex = newHighIndex; // not know at runtime
double data[highIndex-lowIndex]; // therefor, this is an error
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I want to use SetFocus function on the window (HWND) that has open dialog box
Will the function fail?
|
|
|
|
|
I believe so. If you want this feature you must make the dialog box non modal. If you are not using MFC I have no clue how to do this so...
John
|
|
|
|
|
John M. Drescher wrote:
If you are not using MFC I have no clue how to do this so...
CreateDialog* - modeless dialogs
DialogBox* - modal dialogs
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
You can hack it. The only thing the modal crap does is set the "WS_DISABLED" window style on the original window. Just remove it
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
That's interesting... As, I know in MFC the handling of modal / modless is completly different.
John
|
|
|
|
|
MFC is just a wrapper around WIN32 API. So, if you take the WIN32 API, then remove 1 parameter (the HWND), you get the MFC API (that then calls the WIN32 API)!
Spy++ can show this effect though. Check out the window styles on a window before a modal dialog is displayed and then after
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
I have downloded a readymade dll from net. I now want to use it in my project.There is a demo code given with the dll on how to use the dll.In this code all the header files of classes defined in the dll are included in the external dependencies folder of the demo project.Do i have to do a similar thing in order to use the dll?If yes how? I went by the traditional method of menu item-Project->Settings->adding .lib file->including the function header in my proj directory but it didnt work.
Pleasecan wnybody solve my doubt?
ITS VERY URGENT!
Sayali
|
|
|
|
|
external dependencies are header files which are not part of project but included from other files in the project. They are automatically added to "external dependencies" folder in the project during compilation, you can't add them manually.
you said it didnt work - can you explain what are errors or warnings.
Saurabh
|
|
|
|
|
Well I have got a dll and an application which uses that dll downloaded from the internet(from site code project.com.u can aslo check it).There is a folder named external dependencies.In this folder all the files of the dll are added.When i tried to do the same thing for my application ,the programme DOESN'T GIVE AN ERROR IN COMPILATION OR THE BUILD PROCESS.But i also cant use the classes from the dll.It then gives a error of not able to open the header file of the class in the dll.(By the way i have included the comment #include "classheader".h in my cpp and h files;where "classheader" is the name of the header file of the class)
I wanted to know how to you link the dll such that its .h files come in the external dependencies folder.Because in the normal implicit and explicit linking which i tried the files are added in the application source and header files only...
please help
|
|
|
|
|
Make sure you add the relevant lib in
Project Settings -> Link -> General -> Object/Library modules
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
I have pointer to some window (HWND). How can I know if the window is blocked by its dialog box. In other words, I need to know if there is open dialog box (modal)
Thanks
|
|
|
|
|
A dialog box is usually a child of the parent application's main window. If the HWND you have is the main window, use EnumChildWindows to enumerate the child windows of the main window. For each child window, use GetClassName to get the window class of the child. Most dialogs have the class name #32770 . This would at least let you know if the application has a dialog open; unfortunately, it doesn't tell you whether the open dialog is modal or not.
Software Zen: delete this;
|
|
|
|
|
Yes the HWND I have is the main window.
I used EnumChildWindows but unfortunately the function does not "see" dialog boxes.
|
|
|
|
|
It sounds like your dialog is therefore a 'top-level' window. You can use EnumWindows in that case. You might try using GetWindowThreadProcessId to compare the process ID's of your main window to other top-level windows. Other top-level windows with the same process ID are probably dialogs opened by the application.
Software Zen: delete this;
|
|
|
|
|
I have a customized menu, which has a background, icon and sidebar.But what I can't accomplish is to remove the white bounding border(what I mean is the thin white rectangular lines surrounded the bottom and top menu item and of course the menu items in between), anyone can provide advices?
Thanks
|
|
|
|
|
We currently working on WLAN Load Balancing Project.
We need to find the RSSI Value b/w the Station(that is going to connect) and AP as well as the Station that have already connected.
I have come to know about the WMI but lack knowledge.
We don't want to develope any drivers rather using some API that provides control over the device.
Any API that do suport such things???.
Any :-DTUTORIALS , link, tips, SDKs are appreciated.
Thanks
Khalid
|
|
|
|
|
I have a singledocument MFC app. In the mainwindow it displays a listview. If you pick an item in that view a couple of docking Toolsbars with views should show a preview and Informations of that item. You know ACDSee? Than you know what I speak of.
I managed to set things up so far and it works. When selection changes the view sends a message (SendMessage()) with an ID to my MainFrame class and that one loads the new information in the preview tool bars (it calls the functions for loading in the toolbar classes).
Now I have the problem that changing selection in the mainview gets a little bit bumpy. When pressing the down key the selection cicles through the view. Without the views the speed is allways the same. With the views it stops sometimes but the speed changes again and again.
What I want is a steady speed.
The other downside is that the toolbars crashes. It is not a fatal error, the toolbars still work but the updated Informations are not displayed anymore. Even the overall appearance of the bars look damaged. I use a class from codeproject for them: CSizingControlBar so its difficult to say if its a problem with that class or a memory / message issue of my app.
Anyway I would be grateful if someone could help me with the first issue, and even more if someone knows something about the second one.
|
|
|
|