|
just a guess, why don't you use std::vector<> ?
|
|
|
|
|
i never used it.
can you give me a link for this topic?
|
|
|
|
|
MSDN : std::vector [^]
std::vector<CMyType> vec;
CMyType o1, o2;
vec.push_back(o1);
vec.push_back(o2);
std::vector<CMyType>::iterator iter;
for (iter = vec.begin(); iter != vec.end(); iter++) {
CMyType obj = *iter;
}
|
|
|
|
|
thanks toxcct
I'll try it
|
|
|
|
|
Alternatively, he could use the boost/tr1 array template as well.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
erfi wrote: how i can call the Row() constructor for this array? is this possible?
It is possible to call the constructor of the row class. It get's invoked automatically on creation of an object.
ex: This code is not optimized. You should be using destructor of the classes to free the total amount of memory being allocated in this process.
#include "stdafx.h"
#include <iostream>
using namespace std;
class Row
{
private:
char *termState;
int *terms;
public:
Row(int length,int mTCount);
void Display();
};
Row::Row(int a,int b)
{
cout<<"Constructor of the row class is invoked"<<endl;
termState=new char[a];
terms=new int[b];
}
void Row::Display ()
{
cout<<"Display of row class";
}
class Table
{
private:
Row *rows[5];
public:
Table(int);
};
Table::Table(int a)
{
for ( int i=0;i<5;i++)
{
rows[i]=new Row (5,10);
rows[i]->Display();
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Table t(10);
return 0;
}
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
thank you _AnShUmAn_
but in your code you write this :
Row *rows[5];
but i need a parametric length for rows, like this:
Table::Table(int a)
{
rows = new Row[a];
}
when i compile this code this error appears :
"error C2512: 'Row' : no appropriate default constructor available"
i think that there is a better way:
i want to delete the Row() constructor and after creating the Row objects dynamically , allocate the memory for Row object's member with a member function of Row.
what do you think ? is this a good way?
|
|
|
|
|
I agree with toxcc - using vectors for stuff like this would be much easier, as they're especially designed to work just like arrays, but to be resizable at runtime
|
|
|
|
|
erfi wrote: "error C2512: 'Row' : no appropriate default constructor available"
try providing a default constructor in your class.
erfi wrote: allocate the memory for Row object's member with a member function of Row.
What's the problem with allocation of memory in the constructor itself.
Here's the code for you:
#include "stdafx.h"
#include <iostream>
using namespace std;
class Row
{
private:
char *termState;
int *terms;
public:
Row()
{
cout<<"In edefau"<<endl;
}
Row(int length,int mTCount);
void Display();
};
Row::Row(int a,int b)
{
cout<<"Constructor of the row class is invoked"<<endl;
termState=new char[a];
terms=new int[b];
}
void Row::Display ()
{
cout<<"Display of row class";
}
class Table
{
private:
Row *rows;
public:
Table(int);
};
Table::Table(int a)
{
rows=new Row [a];
rows->Display();
}
int _tmain(int argc, _TCHAR* argv[])
{
Table t(10);
return 0;
}
Try this out and let me know whether there exist some more problem..
-- modified at 9:42 Wednesday 20th September, 2006
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
dude, stop trying to reinvent the wheel. the STL provides all this already, in a better way...
consider using vector
|
|
|
|
|
I want to copy a .ini file created using CStdioFile class, I want to copy the entire file to another similar .ini file. How shall I do this?
|
|
|
|
|
Sonia Horra wrote: want to copy the entire file to another similar .ini file
CopyFile()
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
|
use win32 function copyFile() ; refer MSDN for complete documentation
|
|
|
|
|
Hi,
Can anyone please tell me, how to know whether an Event is already signalled or not.
I have an application(App01) which has an event, and checks if it is signalled using " WaitForSingleObject(mhEvent,0);"
Another Application(App02) signals App01, and it works in such a way that a switch is established and App01 just checks if this switch is on/off, and based on that it does all the processing required.
In App02 i am using OpenEvent(..) to get access to the Event created in App01. But before I call SetEvent() or ResetEvent(), I want to know whether the Event(in App01) is already signalled or not.
If it is already signalled, I would'nt need to call SetEvent() again.
this is same with the ResetEvenet().
App02 is a console app, and exits once Set/Reset is done on the App01 Event.
Any suggestions will be appreciated.
Thanks in Advance.
Thanks & Regards,
Dhana
|
|
|
|
|
I do not know of such a function. Try using a Semaphore instead. Initialize it whith a value of 1. Whenever an instance of App2 wants to Signal App1, it decreases the Semaphore by one and then signals to App1 using the Event. App1 then checks the Semaphore. If it is 0, then it does all its calculation, resets the even (better would be an auto-reset event), and then increases the semaphore again. This way, you automatically implement a queue for all instances of App2, that want to signal App1. No signal is lost. Of course, i do not know if that was what you intended.
If you wanted to check because of performance issues, you can neglect that. Conditional execution creates performanceoverhead itself, and a vain call to SetEvent() will not matter. In any case App2 should not be the one to reset the Event. App1 should always do that, to indicate that it is waiting.
Hope that helped a little.
|
|
|
|
|
Thanks for reply.
But the requirement is that i work with App02 and not touch any code in App01. So I cannot add any codes in App01.
Now when Event is signalled from App02, there must be some mechanism on the OS side so that it keeps record of the signal and when App01 WaitForSingleObject(mhEvent,0) is called it will be able to read that it has been signalled. I want to know if there is an structure/any thing else which i can access from App02 and know if it(App02) had signalled App01 in a previous run.
Thank You.
Thanks & Regards,
Dhana
|
|
|
|
|
Greetings all,
I have a problem with my namespace extension that is really causing me problems.
The namespace extension is fairly standard, I use the Shell View created by SHCreateShellFolderView in my IShellFolder::CreateViewObject function.
Here's the problem- every time the user double clicks a subfolder of my extension, a NEW view window is created- it's not shown in the same window. I've tried using only one static instance of the IShellView created by SHCreateShellFolderView in every CreateViewObject function, but when I do this, when the user double clicks on the subfolder they don't navigate into it, they remain in the same folder.
This is really holding my project back at the moment, please everyone any ideas would be enormously appreciated!
Thanks in advance,
Dave Kerr
codechamber@hotmail.com
http://www.codechamber.com
|
|
|
|
|
I've found the following page in msdn:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/CommonDialogBoxLibrary/CommonDialogBoxReference/CommonDialogBoxFunctions/GetOpenFileName.asp
Which describes how to call an open folder dialog box through the .NET framework. Is it possible to avoid having to use this syntax and call the open folder dialog box directly on the win32 api? Similar to how I'd call MessageBox() for instances?
|
|
|
|
|
No, it doesn't. It tells you how to do it using Win32. This IS the direct way of doing it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
What am I missing here at the top of that page it says:
.NET Framework Class Library
FolderBrowserDialog Class
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.
and than in the c++ example you have to inherit the following class System.Windows.Forms.Form
Am I just being very dim and missing the painfully obvious or does the above page not describe how to open a folder dialog using the .Net framework rather then just being able to directly call a function which is in one of the win32 dlls in the same fashion as you'd call GetOpenFileName()?
|
|
|
|
|
in the link you provided there is no trace of .net....
|
|
|
|
|
Ah I'm an idiot, This is what I ment to paste I had the other window open as it was looking at using that as well.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsfolderbrowserdialogclasstopic.asp
|
|
|
|
|
Hi all,
How does one profile timing for VS 6.0? Does it give you the timing in seconds or percentage? I would like to have timing in seconds, how do i obtain that?
How does one repeate the above for VS 9.0?
I do understand this might be the wrong forum to post this question but I am not getting the answer in the right forum, so I thought here I could grab some attention.
|
|
|
|