|
OK, well, it CAN'T work in VC6. In VC2005, you need to provide a little more information if you want people to be able to help you. What did it do ? What version are you using ? What's the code look like ( it looks to me like your original snippet is missing some stuff ).
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
fx9200 wrote: ...it dosen't work also in .net studio
Why not? What's the problem? Copying code and then saying it doesn't work is not very helpful.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
That's Managed C++ syntax, not C++/CLI. It'll work directly in VS2003, but for 2005, you'll need to use the /clr:oldSyntax switch.
|
|
|
|
|
Hi all,
I'm trying to use a DLL compiled with VS2005 C++ with a .exe compiled in VC6, and although the .exe compiles and links with no problem, when I run it it crashes on trying to access the DLL.
Any ideas?
Steve.
Asynes yw brassa ages kwilkynyow.
|
|
|
|
|
viaduct wrote: Any ideas?
No but if you use your debugger, you'll have a lot more information of what's happening.
|
|
|
|
|
Erm, not sure if you're taking the piss there, but I had actually thought of that myself. The crash occurs at the end of a massive stack of system calls with only addresses and no function names, so there isn't much to go on.
Asynes yw brassa ages kwilkynyow.
|
|
|
|
|
Mmmh, one thing that comes to my mind: did you check if they are both linked to the same run-time library ? (single threaded, multi-threaded, ...)
|
|
|
|
|
To turn those addresses into function names, you need the debugging symbols for the OS. See here[^] for how to set up VS2005 to automatically grab the matching debugging symbols from a Microsoft web server, as required.
|
|
|
|
|
char *p= "test string";
p[5] = '_';
This code will fail. why?
My Assumption: "test string" remaining in memory as a constant pointer, hence it modifying teh same fails.
it would be helpful if you let me know how compiler handling such definitions and how it resides in memory
|
|
|
|
|
String literals are constant. For historical reasons you can use char * (when you really should only be able to use const char * ) in this case.
See here[^] to see what Microsoft has to say about this.
|
|
|
|
|
Sarath.<fon wrote:<="" div="">This code will fail. why?
It's the difference between arrays and pointers. Had you used the following, it would have worked:
char p[] = "test string";
p[5] = '_';
|
|
|
|
|
Just an FYI:
It is VERY bad to declare an array this way and then modify it. In this case, it won't hurt anything, but lets say you tried something like:
char p[] = "hello";<br />
p[5] = ',';<br />
p[6] = ' ';<br />
p[7] = 'W';<br />
p[8] = 'o';<br />
p[9] = 'r';<br />
p[10] = 'l';<br />
p[11] = 'd';
Now you have overwritten parts in memory that were not allocated for that string. With few exceptions, you should always specify a size for your arrays:
char p[30] = "hello, world!";
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
|
|
|
|
|
I think, Null char to be added to p[12].
|
|
|
|
|
You can think it, but it'd still be wrong.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Adding NULL to p[12] would still cause a segmentation fault (aka crash). Since the array was not declared with any bounds, it defaults to the size of the initailized string (which is 6 for "hello"). Any character that is written past that size is overwriting something in memory that may or may not be important. If it overwrites, for example, the next instruction on the stack ... you get the idea. The point is, you should always declare arrays with a size.
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
|
|
|
|
|
Hello,
Writing windows service in c++.Net 2005 it’s clear, but I’ve problems when I
Want to write a windows service in C++.Net 2005 but with unmanaged code.
I’ll appreciate if anyone can give me a clue/hint.
Thanks
|
|
|
|
|
yosm wrote: but I’ve problems
yosm wrote: I’ll appreciate if anyone can give me a clue/hint.
HINT: You did not state any specific "problem".
|
|
|
|
|
Hi
I know overloading is and i know overriding in virtual functions.But when i overload an overriding functions, something differnet.
<br />
#include <iostream><br />
<br />
using namespace std;<br />
class CBase<br />
{<br />
public:<br />
virtual void func(char n)<br />
{<br />
cout << "base";<br />
};<br />
<br />
};<br />
<br />
class CDerived : public CBase<br />
{<br />
public:<br />
virtual void func(int n)<br />
{<br />
cout << " derived";<br />
}<br />
};<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
CBase* BaseForDerived = new CDerived;<br />
double y=123.45;<br />
int n=100;<br />
long d= 9;<br />
BaseForDerived->func(y);<br />
BaseForDerived->func(n);<br />
BaseForDerived->func(d);<br />
CDerived x;<br />
x.func('c');<br />
delete BaseForDerived;<br />
}<br />
Here if i write virtual void func(int n) instead of virtual void func(char n) it shows me derived for all.For first 3 it shows me base the last it shows me derived.But i confused.
Does overloading a virtual function ,in derived class mean a new function declariton?
If so why it shows me for x.func('c'); derived but not BASE.
If not why this code shows me for func() base class.I gave int parameter.
I really confused.
I am looking for your answers.
Thanks.
|
|
|
|
|
Late in C++ standardisation, the type of a single-character literal was changed from int (as it is in C89) to char . You may be using an out-of-date compiler which has not yet reflected this change.
|
|
|
|
|
What you are doing is called hiding. The rules the compiler uses for resolving which method you want have problems when you do this. Scott Meyers gives a good explanation of this in his Effective C++ book.
Basically, since char and int can be implicitly casted to each other, your overload hides the method and makes it almost impossible for the compiler to pick the correct method (it is not a mind reader afterall).
To avoid this issue, write code like this instead:
class Base
{
public:
virtual void func(char n)
{
cout << "base" << endl;
}
};
class Derived : public Base
{
public:
virtual void func(char c)
{
gfunc(9);
}
virtual void gfunc(int n)
{
cout << "derived" << endl;
}
};
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
|
|
|
|
|
Hello all
I am developing dialog based application. I have written a function in main dialog class and I want to access that in other classes. How to access this function in difffernt dialogs "onInitDialog()" function
regards,
Aj
|
|
|
|
|
Hey....Simply create an object to that main dialog and call the function.
If you want to call the function of main dialog from its child dialog then the child oen have a member m_pParentWnd to the MainDialog
Then simply call
m_pParentWnd->GetFunction();
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
Thanks for reply. can you please explain in detail that will help me.
I am developing dialog based application. I have written a function in main dialog class(TestDlg.cpp) on button click i am opening new dialog (Say child.cpp ) I want to access the fuction from main dialog (TestDlg.cpp) from child.cpp. How to access the function from
|
|
|
|
|
if main dialog is CMain and other class is CLocal you can use in local class CMain* m_Main=(CMain*)GetParent(); m_Main->your_variable or your_function(and also include "Main.h" in other classess)
|
|
|
|
|
I tried this
CMain* m_Main=(CMain*)GetParent();
m_Main->Test(1);
Test is function decleareed in CMainDlg;
also CMainDlg.h included in child dialog class.
it gives following errors;
'm_Main': identifier not found, even with argument-dependent lookup
'CMainDlg' : undeclared identifier
'm_Main' : undeclared identifier
left of '->Test' must point to class/struct/union
‘CMainDlg’: identifier not found, even with argument-dependent lookup
|
|
|
|