|
Hi Matthew,
1.
Matthew Faithfull wrote: you couldn't do it in VC6
I am using Visual Studio 2008.
2.
Matthew Faithfull wrote: namespace polluting #defines
Why it is namespace polluting? It is defined in the global/default namespace?
regards,
George
|
|
|
|
|
George_George wrote: Why it is namespace polluting? It is defined in the global/default namespace?
Exactly because it's defined in the global/default namespace and it is NOT really global or shouldn't be. What if I include a third party header file which also has
#define DEFAULT_ARRAYSIZE 400 - potential disaster.
One of the principles of good OO programming is 'locality of reference' which basically means a name should only be defined for the scope where it is meant to be used. That was the whole point of introducing namespace into C++ (which also didn't work in VC6) so that myLib::CString could exist in the same project as CString from MFC and the correct reference can always be resolved rather than refering to whichever one was included first or most recently.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Matthew Faithfull wrote: which basically means a name should only be defined for the scope where it is meant to be used.
No that is not what the Locality of Reference or Principle of Locality[^] is about at all.
In computer science, locality of reference, also known as the principle of locality, is the phenomenon of the same value or related storage locations being frequently accessed. There are three basic types of locality of reference: temporal, spatial and sequential:
led mike
|
|
|
|
|
Four types, the fourth being codespace, scope and extent, the principle is exactly the same it's just another virtual dimensionality.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Matthew Faithfull wrote: Four types, the fourth being codespace
Do you have a citation for that or are you asking use to recognize you as a leader in the industry capable of establishing Principles?
led mike
|
|
|
|
|
Thanks Matthew,
So, your answer to my original question is, it is according to C++ Spec that non-const static variable is not allowed to be initialized at the time when it is declared, right?
I am interested in what the Spec says, could you help to quote the related C++ Spec please?
regards,
George
|
|
|
|
|
Hi,
The 2005 compiler alsoo treats this as an error.
Now the why (Found this on the Net[^]):
"If a static data member is of const integral or const enumeration type, its
declaration in the class definition can specify a constant-initializer which
shall be an integral constant expression. In that case, the member can
appear in integral constant expressions within its scope. The member shall
still be defined in a namespace scope if it is used in the program and the
namespace scope definition shall not contain an initializer."
So the only relaxation is that for static const integral/enum types you can
get away with the definition if you don't use them in their program i.e.
don't treat them as l-values. The key point you are missing is that the
member can still appear in integral constant expressions (like case label).
So this clause is just a relaxation applicable only with integral constant
expressions.
I think the next sample while explain it more:
class MaxBuffer
{
public:
const static int Max = 80;
int m_iBuffer[Max];
};
class ErrorBuffer
{
public:
static int Max;
int m_iBuffer[Max];
};
codito ergo sum
|
|
|
|
|
Thanks BadKarma,
1.
I read the document you quoted. What means "integral constant expression"?
2.
BadKarma wrote: don't treat them as l-values
Means for const static member variable, they are not l-value? Actually, I do not agree since for the const static member variable, it is addressable, so it should be a l-value.
Here is my code to verify,
class Foo{
public:
const static int size = 100;
};
int main()
{
cout << &(Foo::size);
return 0;
}
regards,
George
|
|
|
|
|
Hi, george_george
George_George wrote: What means "integral constant expression"?
They are alsoo known as compile time constants. Look at int const guidelines (boost)[^]
George_George wrote: Means for const static member variable, they are not l-value? Actually, I do not agree since for the const static member variable, it is addressable, so it should be a l-value.
This is not correct.
The meaning of l-value is : on the left side of an assignment.
Since its a const it can't be on the left side. Whether you got the address where that value
is stored doesn't matter. If you try to use it in any way on the left side of an expression
you would have an access violation. I'm guessing the value is placed in an read only segment
of memory.
codito ergo sum
|
|
|
|
|
Thanks BadKarma!
Great reply. I have re-read what you quoted in the Spec before, I am confused about what does the following statement mean?
(what makes me confused is in a class, which type of statement could be looked as definition, and which type of statement could be looked as declaration?)
"get away with the definition if you don't use them in their program"
regards,
George
|
|
|
|
|
Sir,
My COM class not getting registered.
Iam trying to register the COM DLL with .regsvr32.
It is not displaying either Dll Registered or Failed messge.
So, when i try to create instance of thet class, using CoCreateInstance
it returned Failure Code -2147221164 , that means Class not registered.
I want to know the reasons of CoCreateInstance failure.
Help me Plz.
Krishna.
|
|
|
|
|
Royaltvk wrote: It is not displaying either Dll Registered or Failed messge.
The above is unusual. Could you debug your DLLRegisterServer function?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Iam trying to debug this COMDll from my application .So that iam trying to crate instance of this COM DLL
just like this
CoInitialize(NULL);<br />
BSTR str;<br />
<br />
IDUOleServerImpl *pDXOLEServer;<br />
<br />
<br />
HRESULT hr = CoCreateInstance(CLSID_DUOleServerImpl, NULL, CLSCTX_ALL,<br />
IID_IDUOleServerImpl, (LPVOID *)&pDXOLEServer);<br />
if( !pDXOLEServer )<br />
{ <br />
szResponse ="Problem in Creating the DXOLE Engine Server";<br />
<br />
return ;<br />
}<br />
<br />
<br />
pDXOLEServer->ExecuteRequest(10001,bstrConnectionInfo,&str);<br />
But in my application is not be able to locate the server and throwing an error code -2147221164 i.e Class not registered.
But If i try to register the COM DLL for CmdLine Regsvr32, it is not throwing any success or failure notice.
Still iam mess up with this problem .
Please look at this.
|
|
|
|
|
U can create COM Object only if it is successfully Registered.
If u r debugging in this way u cannot find out the installation problem.
u need to debug the DLL while registering it.
Royaltvk wrote: But If i try to register the COM DLL for CmdLine Regsvr32, it is not throwing any success or failure notice.
may be this is because infinite loop, deadlock in the registration path
|
|
|
|
|
Please read CPallini's reply again. He said:
The above is unusual. Could you debug your DLLRegisterServer function?
If your DLL isn't registering properly, then of course CreateInstance won;t work!
Regedit is also your friend - you can see if the keys you need for registration are being created.
Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
|
|
|
|
|
if u don't know how to debug the DLLRegisterServer, following may be useful,
1) put a breakpoint in your DLLRegisterServer function
2) Set your COM DLL project as Startup project
3) IN your COM DLL project Settings set the values such that regsvr32.exe is started,
vsproperty->Debugging->Command = C:\WINDOWS\system32\regsvr32.exe
vsproperty->Debugging->Command Arguments = "$(TargetPath)" // path to COM DLL
4) start debugging
|
|
|
|
|
I am making a small dialog based application where i have an edit box. what needs to be done to display the value that is typed in the editbox. i want the messagebox to dispay the vlaue that is texted. i dont want to use the OK button. click and if the focus is lost the the value should display. any leads.
|
|
|
|
|
Chandrasekharanp wrote: if the focus is lost the the value should display.
Have you tried EN_KILLFOCUS ?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
yes i have tried EN_KILLFOCUS. i am not getting the right result. is there any other way?
|
|
|
|
|
EN_KILLFOCUS did help me in solving the problem. the logic which i gave was wrong.
Thanks
|
|
|
|
|
Why you didnt make your dialog instead use of messagebox?
|
|
|
|
|
Hello
I am working on vc++ project in which i want to create the sql connection with my MFC application, so that i can create a new sql database (.mdf file)
Is there any way to create a connection with sql server 2000 in VC++
and we also make a new sql database (.mdf) file .
kindly look into the matter
thanks
|
|
|
|
|
Hi,
its possible by using ado. In order to do let it work, you must preform some setup tasks.
1. Import the Library
place the following line in the stdafx.h file. the msado15.dll file should be located in the project directory.
#import "msado15.dll" no_namespace rename ("EOF", "adoEOF")
2. Initialize the ole lib
Ado works with oledb.
if(OleInitialize(NULL) != S_OK)
{
}
3. Connect to the database
Replace USER_ID, PASSWORD, SQLSERVERNAME, DATABASE_NAME with the correct values
CString strConnectionString;
strConnectionString.Format("uid=USER_ID;pwd=PASSWORD;driver={SQL Server};server=SQLSERVERNAME;database=DATABASE_NAME");
_ConnectionPtr ptrDbCon;
ptrDbCon.CreateInstance(__uuidof(Connection));
ptrDbCon->Open((_bstr_t)strConnectionString, "", "", -1);
<code></code>
You sould connect to the master database in order to create another database.
Just execute the queries to create an database as you need.
codito ergo sum
|
|
|
|
|
Thanks for your reply
as per your saying i connect the master database in order to create another database.but i don't know how i execute the query to create a new database
kindly give me the sample code or any syntax how to proceed further
thanks
|
|
|
|
|
Have you tried using the CREATE DATABASE command?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|