|
minkowski wrote: It just copies the address and does not involve using copy constructors?
Yes, no copy constructor are involved. In fact, no constructor at all will be called, because you don't construct a new object. You only delete an object (when the function goes out of scope) and then return its address. Which is of course very very bad .
|
|
|
|
|
Ok thanks!
|
|
|
|
|
minkowski wrote:
alpha * func()
{
alpha anything;
alpha *ptr = &anything;
return ptr;
} how would it return ptr. Would it copy the pointer ptr using the copy constructor and then destroy it as the function goes out of scope?
The type you return is pointer. In this case, pointer to alpha.
And pointers do not have such things as copy constructors.
So, no copy c'tor is called.
Failure is not an option - it's built right in.
|
|
|
|
|
I have a c++ project in VC2005
------------------------------
try.h
#include <stdafx.h>
public class TryIt {
int i;
public:
void test(void);
};
------------------------------
try.cpp
#include "try.h"
#include "stdafx.h"
void TryIt::test() {
int i = 5;
}
------------------------------
both files in the project folder
but I always get
c:\vcproj\audit\audit\try.cpp(4) : error C2653: 'TryIt' : is not a class or namespace name
Any idea?
Nathan
|
|
|
|
|
Hi,
Hope this will help: From VS2005 Documentation
Error Message
'identifier' : is not a class or namespace name
Syntax requires a class, structure, union, or namespace name.
The following sample generates C2653:
class yy {
void func1(int i);
};
void xx::func1(int m) {}
void yy::func1(int m) {}
C2653 is also possible if you try to define a compound namespace; compound namespaces are not allowed in C++:
namespace a::b {int i;}
namespace a {
namespace b {
int i;
}
}
int main() {
a::b::i = 2;
}
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
not sure if that will help, but in your try.h, you don't provide exclusive inclusion like this :
#ifndef __A_VERY_LONG_AND_UNIQUE_NAME__
#define __A_VERY_LONG_AND_UNIQUE_NAME__
#endif
BTW, looking at your error, i would say that you don't include un try.cpp the header try.h, but looking at your sample, you do it, so...
|
|
|
|
|
try:
<br />
------------------------------<br />
try.h<br />
#include <br />
<br />
class TryIt {<br />
int i;<br />
<br />
public:<br />
void test(void);<br />
};<br />
------------------------------<br />
try.cpp<br />
#include "stdafx.h"<br />
#include "try.h"<br />
<br />
void TryIt::test() {<br />
int i = 5;<br />
}<br />
------------------------------<br />
I have removed the public from the class definition (I'm not sure what a private class would be?) - I suspect this is the problem. Also, I changed the order of the include files - if you are using precompiled headers stdafx.h must be first. This is probably not the issue as you would get a different error message, but probably good practice.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
cp9876 wrote: if you are using precompiled headers stdafx.h must be first. This is probably not the issue as you would get a different error message, but probably good practice.
Actually that is exactly the issue. Everything before #include "stdafx.h" gets ignored by the preprocessor.
|
|
|
|
|
Michael Dunn wrote: Everything before #include "stdafx.h" gets ignored by the preprocessor.
Huh? I thought everything up to and including the specified filename (stdafx.h by default) is
precompiled.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mike's right - from MSDN:[^]
------------------------------------------------------------
AppWizard puts the line "#include 'stdafx.h'" as one of the first lines in every .CPP file in a project. Because of the compiler options being used by projects generated with AppWizard, anything up to and including "stdafx.h" in a .CPP file is considered by the compiler to be part of a precompiled header.
The problem with this is that when you edit the .CPP files and insert #includes, #defines, declarations, or other code before the "#include 'stdafx.h'" line, all of it is ignored by the compiler. This is the correct behavior because when the compiler is using the precompiled header, it starts to compile the code in the .CPP file after skipping past the "stdafx.h" line.
This behavior can lead to compiler errors that do not seem to make sense, because it appears that you are including all the needed declarations and header files in the .CPP file. For example, some of the errors that may result are the following:
• error C2065: 'CTestClass' : undeclared identifier
• error C2146: syntax error : missing ';' before identifier 'tc'
• error C2064: term does not evaluate to a function
------------------------------------------------------------
The last time I made this mistake was in VC6, and there, if I recall correctly, the compiler clagged - gave some warning that the include files up to stdafx.h did not match those it precompiled.
By the way, what is a 'public class', I know that for nested classes you can have public / private etc, but in global scope? What would a private class do?
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Hi Peter, I also don't kown the private/public issue, anyway I use the class wizard to add the TryIt class, it worked
|
|
|
|
|
cp9876 wrote: The problem with this is that when you edit the .CPP files and insert #includes, #defines, declarations, or other code before the "#include 'stdafx.h'" line, all of it is ignored by the compiler. This is the correct behavior because when the compiler is using the precompiled header, it starts to compile the code in the .CPP file after skipping past the "stdafx.h" line.
Ok I gotcha. I was thinking of when the precompiled header is precompiled, everything
through the indicated file is precompiled.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: Ok I gotcha. I was thinking of when the precompiled header is precompiled, everything
through the indicated file is precompiled
Your thinking is correct. Given that the precompiled header options were not changed from the defaults that VS uses, the precompiled header was created when stdafx.cpp was compiled. The OP probably added his includes in a "real" source file, not stdafx.cpp. In that case, everything prior to "#include stdafx.h" is ignored. If the #include for the class in question had been added to stdafx.cpp before the usual single line #include "stdafx.h" , it would have worked.
Just for posterity's sake if someone searches for this thread ... I do not recommend changing stdafx.cpp. If something needs to be included in every file in the project, change YourProjectApp.h or stdafx.h
Judy
|
|
|
|
|
Thanks Judy!
I was confused taking the comment out of context (or sticking my nose in something not my
business, depending on how one looks at it).
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: (or sticking my nose in something not my
business, depending on how one looks at it).
That's what we all do - note that I hadn't been involved in this thread until I responded to you. You usually seem to know what you're doing and you sounded confused, so I stuck my nose in to rememdy your confusion.
Judy
|
|
|
|
|
I think this comment in MSDN is pretty poor:
--------------------------------------------------------
This behavior can lead to compiler errors that do not seem to make sense, because it appears that you are including all the needed declarations and header files in the .CPP file. For example, some of the errors that may result are the following:
• error C2065: 'CTestClass' : undeclared identifier
• error C2146: syntax error : missing ';' before identifier 'tc'
• error C2064: term does not evaluate to a function
--------------------------------------------------------
surely this should have been a signal to someone that their precompiled header logic needs some improvement - simply checking that the headers precompiled in the top level file would trap most mistakes.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
cp9876 wrote: By the way, what is a 'public class', I know that for nested classes you can have public / private etc, but in global scope? What would a private class do?
Having public there isn't legal C++, it's probably the poster's Java and/or C# habits showing in his C++
|
|
|
|
|
Hi everybody,
i add controls dynamically on a CDialog.
The font of each control is bold and too big. (CStatic,CComboBox and CEdit)
The font of the Dialog is set to "Ms Shell Dlg (8)" ... not bold or too big
Does anyone have an idea?
Thanks
|
|
|
|
|
Hi!
May be you should get font of dialog and set it on all child controlls manually. I mean some like that:
CDialog * pDlg; //already init
CFont * pF = 0;
pDlg->GetFont(pF);
...
ChildWindowPtr->SetFont(pF);
Best regards,
Baron
|
|
|
|
|
If you want to change font you can use of SetFont and also you can use of CreateFont for new font.Is this helpfuls?
|
|
|
|
|
Thanks for your replies.
The way over the pointer to the Font of the Dialog seems not to work
CDialog * pDlg; //already init
CFont * pF = 0;
pDlg->GetFont(pF);
I created my own Font and associate it to new controls, which works now
|
|
|
|
|
And when you create font in the end use of DeleteObject function to delete it.;)
|
|
|
|
|
Hi All,
How do i know whether DHCP(Dynamic Host Configuration Protocol)is complete after an ethernet cable is plugged into my system?
I am using VC++(VS2005). Is there any kind of callback or any API to determine this?
Any suggestions? Please help
Sunil
|
|
|
|
|
Hi
I want to open a form from a running form, how is that done ?
Regards
|
|
|
|
|
Hi,
you try to open a CDialog deriven form, or change a view into a Frame, or
open a new Frame within a new view?
I try to help you at my best
|
|
|
|