|
Hi,
I have this
char* author_name[m]; //m=30
as private member data.
If I want to access it ,How should I use it?
I use as cin>>author_name[m];
It shows an err that unexceptional err handeled
Rupali Sarda
|
|
|
|
|
Duplicate your post won't help you to get better responses. Some people already responded to your previous question so why repost it ?
If the answers are those you are looking for, then reply and try to give more precisions. We don't know what is the error, we don't know what you are trying to do, we don't know if it is a compile error or runtime error, ....
|
|
|
|
|
cedric moonen wrote:
Duplicate your post won't help you to get better responses. Some people already responded to your previous question so why repost it ?
perfectly, this worthes a '1'
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
its answered already see your previous post
|
|
|
|
|
yes it will show u error
char*author_name[m]//m=30
as it is an array of pointers of type char
so
cin>>author_name[m],say m=30
author_name[m] expecting an address whereas u r trying to fill characters
|
|
|
|
|
sunit5 wrote:
char*author_name[m]//m=30
as it is an array of pointers of type char
Check one thing.....
char*author_name[m]//m=30 is just pointer of UnIntialized array...., so if we try to access a Unintialized memory... it always throws the error...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Well, since he's actually writing to the memory it doesn't matter if it's initalized or not. As long as it is allocated everything is fine.
Of course, he has to check that he doesn't write more than m-1 chars into author_name, but that's unrelated to initialization.
Sorry! Forget it! I didn't see that it's an array of pointers, I took it as a char array. You're absolutely right that access to uninititalized pointers will give you problems.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
-- modified at 5:19 Friday 23rd September, 2005
|
|
|
|
|
Steen Krogsgaard wrote:
As long as it is allocated everything is fine.
I believe He/She haven't allocated the memory for that yet.....
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Yes, my mistake, please se the modification I made to my previous post
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Steen Krogsgaard wrote:
Yes, my mistake,
It's OK, Sir..
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
sir,
i am confused about pure virtual function .why it is needed in abstract base class. in which cases it is use.
plz tell me about pure virtual function & abstract base class
|
|
|
|
|
Pure virtual functions can be used to force other developper who will create classes inherited of your class to define this specific function. If this developper implemented a class that inherits yours and didn't implement the function, whenever you try to instantiate this class, the compiler will generate an error saying that the function has not been define in the inherited class.
It's a way to ensure that all child classes will implement their own virtual function.
|
|
|
|
|
You may think of an abstract base class as an interface. The interface defines how inherited classes are utilized.
The base class is abstract and hence cannot be created. The same goes for interfaces: there's no point in create an interface unless there's an object behind it.
This is also how COM interfaces are defined in C++.
aloktambi wrote:
why it is needed in abstract base class.
Without a pure virtual function the class is not abstract.
|
|
|
|
|
Here's an example of something I did with an abstract base class. This class was a thread class that would start up the thread. It was its own class because that would allow derived instances of it to have their own set of properties and capabilities in addition to those supplied by the base class. The pure virtual methd of the class is the thread procedure itself. One makes their own thread objects by deriving from this base class and implementing the thread procedure method. Other methods are available to create the thread, to initialize it, and to clean up after it. Each of those mentioned are virtual to allow them to be overridden but they also have default implementations. In the case of the thread procedure method a thread is useless without one so making it a pure virtual method requires all derived class to provide an implementation of it.
Does this makes sense ?
BTW - about this thread class, normally class methods can't be used as thread procedures but these threads use a static member method as the thread procedure and its argument is the this pointer of the thread object. The static member method calls the derived class' thread procedure method.
|
|
|
|
|
cedric moonen is right...
Here Why you need Abstract class..
Consider the basic senario of having shape classes like Line, Rectangle, etc.
In the real world, there is nothing called Shape... you cannot define a Shape,, The object could be regular, irregular... But you cannot not define Shape anywhere...
Line is a Shape
Circle is a Shape
Rectangle is a Shape
But Shape is not Shape... (U might confused more..if it is i am really sorry )
But if you look at Line, Circle, Rectangle they are measarable..ie you can find area, they will have line length, width, color, style etc.. So considering these features we have, all are put in to a Shape class in order to resuse the existing implementation...
But as I told Shape is not Shape... You cannot draw a Shape.. So you need to protect the user to create Shape object...For that you need to make that class as abstract ie it must to have a pure virtual function,
Pure virtual function doesn't has implementation (In c++ context)
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
Its quiet simple
It forces the programer to define the
function in the dervied class that is a pure
virtual fun in the base class.
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hi,
I have an private mem as char* author_name[30];
If I want to take input from user then How should I use this in cin>> syntax?
Error:
I m using cin>>author_name[30];
It shows an unexceptional error occur.
Rupali Sarda
|
|
|
|
|
You get an exception because you declared a pointer to a pointer, it's like declaring char** .
You have no memory allocated for that pointer so cin>> will atempt to write in some random memory location.
|
|
|
|
|
To complete previous response, it will work if you remove the *:
char author_name[30];
And then:
cin>>author_name;
|
|
|
|
|
As it is a private member, u cant use like this cin>>author_name.because private member r accesible throug h their member function ,friend function,friend class.
better u create char pointer say
char input_user[30];
cin>>input_user;
say the private member is defined in a class
Class AUTHOR_NAME
{
public:
author_name(char name) //constructor
{strcpy(author_name,name);}
private: char author_name[30];//private member
};
-- modified at 2:13 Friday 23rd September, 2005
|
|
|
|
|
Rupali sarda wrote:
have an private mem as char* author_name[30];
here is small program for you.....
void main()
{
char *name[30];
for(int i=0;i<2;i++)
{
name[i]=new char[30];
cin>>name[i];
}
for(i=0;i<2;i++)
{
cout<<name[i];
delete [] name[i];
}
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
welcome simple but nice one !
V
|
|
|
|
|
Hi,
In my application i've few edit boxes ,the value in them can be edited by the user during runtime.i've set a limit for the number of integers they can enter and after the user enters the value i want to trap them in a SINGLE CLICK message handler.I dont want to use EN_CHANGE handlerfor this.will it be possible for me to do it this way?
thank you in advance.
rajeev
|
|
|
|
|
A way to do that is to derive a class from CEdit and in that class trap the WM_LBUTTONDOWN message. From the WM_LBUTTONDOWN handler notify the parent about the event and that's it. The edit boxes from your application have to be instances of your derived class.
|
|
|
|
|
Dear all,
I have created a process and wait for it to complete a certain job. e.g. "Driver Installation".
When the driver installs, it will request the user to re-start (or skip) your PC. If you choose not to re-start your PC; the main process will continue the incomplete job. On the contrary, if you choose to re-start the PC, the system will cause “Circular Wait”. Because the process informs main process whether the session is ending. In this case- how should I know if the process shows that I need to re-start the computer? If the main process has received the reboot message and then just go to leave.
SHELLEXECUTEINFO ExecuteInfoDriver;
memset(&ExecuteInfoDriver, 0, sizeof(ExecuteInfoDriver));
LPCTSTR lpctDriverPath = (LPCTSTR)DriverPath;
ExecuteInfoDriver.cbSize = sizeof(ExecuteInfoDriver);
ExecuteInfoDriver.fMask = SEE_MASK_NOCLOSEPROCESS;
ExecuteInfoDriver.hwnd = 0;
ExecuteInfoDriver.lpVerb = "open";
ExecuteInfoDriver.lpFile = lpctDriverPath;
ExecuteInfoDriver.lpParameters = NULL;
ExecuteInfoDriver.lpDirectory = 0;
ExecuteInfoDriver.nShow = SW_SHOW;
ExecuteInfoDriver.hInstApp = 0;
......
if (::ShellExecuteEx(&ExecuteInfoDriver))
{
hDriverProcess = ExecuteInfoDriver.hProcess;
if (hDriverProcess != NULL)
{
::WaitForSingleObject(hDriverProcess, INFINITE);
::CloseHandle(hDriverProcess);
}
}
....
do something...
....
Thanks for your help, I really appreciate it.
Best Regards
Steve Chang.
|
|
|
|