|
hello
i want to know,
1)how to create User DSN in ODBC
2)& how to register .ocx file through install shield for vc++ 6
regards
Chanda.com
|
|
|
|
|
Chanda.com wrote:
how to register .ocx file through install shield for vc++ 6
Mostly they are "self-register",you have to only check that
ocx as self register in your installshield
Chanda.com wrote:
how to create User DSN in ODBC
Check SQLCreateDataSource
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
class string {
public:
string(const char *value);
~string();
private:
char *data;
};
string::string(const char *value)
{
if (value) {
data = new char[strlen(value) + 1];
strcpy(data, value);
}
else {
data = new char[1];
*data = '\0';
}
}
inline string::~string() { delete [] data; }
void donothing1(string localstring) {}
void donothing2(string& localstring) {}
main()
{
string s1 = "the truth is out there";
donothing1(s1);
string s2 = "the truth is out there, too";
donothing1(s2);
}
I'm amumu, and you?
|
|
|
|
|
By calling:
<br />
string s1 = "the truth is out there";<br />
you are first invoking the default constructor of the string class, which you have not defined, so string::data is also undefined.
Next the operator= is invoked to assign "the truth is out there" to your object. This function is also undefined, therefore the default implementation is used and it will copy the pointer value that you sent in straight across. This is called a shallow copy, and it is generally bad.
If you want the code that you wrote to work, with out worrying about the shallow copy problem, you could make this change to the way that you invoke your objects:
<br />
string s1("the truth is out there";<br />
This will invoke the constructor that you have defined.
If you are going to have dynamically allocated data in any class, you should define these four functions, that will be automatically provided by the compiler if you do not choose to implement them yourself:
Default Constructor
string()
{
data = NULL;
}
Destructor
string()
{
delete[] data;
data = NULL;
}
Copy Constructor
string(const string& rhs)
{
if (rhs.data)
{
UINT nLen = strlen(rhs.data);
data = new char[nLen+1];
strcpy(data, rhs.data);
}
else
{
data = NULL;
}
}
Finally...
Assignment operator
string &operator=(const string& rhs)
{
if (this == &rhs)
{
return *this;
}
delete[] data;
if (rhs.data)
{
UINT nLen = strlen(rhs.data);
data = new char[nLen+1];
strcpy(data, rhs.data);
}
else
{
data = NULL;
}
return *this;
}
I have included a basic implementation of how it is done in order to set you onto the right track.
|
|
|
|
|
This is a technicality, but it might be worth mentioning:
string s1 = "the truth is out there"; You said that this sentence involves the default ctor and the assignment operation. In fact, none of these two is called here. The sequence is:- A temporary object is constructed from
"the truth is out there" using string::string(const char *) .
s1 is constructed from this temporary object using the copy ctor. The compiler is allowed to optimize away the temporary and the call to the copy ctor, as in fact VC++ does*. So, for our particular scenario, only string::string(const char *) is involved in the sentence.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
* The thing is rather complicated: for the optimization to be allowed it is necessary that the copy ctor be accesible (i.e. not private ). VC++, however, only conforms to this rule if MS proprietary extensions to the language are disabled (/Za).
|
|
|
|
|
Because string has no copy constructor, when the donothing1 invoked, compiler will create a temporary object, and invoke the default copy contructor, so, the temporary object will copy the point "data" from localstring, and when the donothing1 is finished, the temporary object will destoried, and the infomation stored in "data" will lost. That's the problem I read from <<effective c++="">>, but what happen when invoke donothing2 function?
I'm amumu, and you?
|
|
|
|
|
I just looked at your code from earlier, you have not invoked the donothing2 function.
qf0421 wrote:
<br />
main()<br />
{<br />
string s1 = "the truth is out there";<br />
<br />
donothing1(s1);<br />
<br />
string s2 = "the truth is out there, too";<br />
<br />
donothing1(s2);<br />
<br />
}<br />
|
|
|
|
|
As donothing2 accepts a reference, there's no copying involved in the calling process, and no problem as those posed by the first function will arise. If you think of a reference (in this context) as an alias for a pointer you'll see more clearly the differences between donothing1 and donothing2 .
Nevertheless, it is very much advisable to explictly write the "gang of four" (default ctor, copy ctor, assignment operator and dtor) for every class wihtout trivial semantics and not leave these holes to the interpretation and good sense of the user.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
A temporary object is constructed from "the truth is out there" using string::string(const char *).
s1 is constructed from this temporary object using the copy ctor.
That is incorrect. The following two lines are exactly the same:
string s1 = "the truth is out there";
string s1 ("the truth is out there"); They both call the one-parameter constructor.
--Mike--
"There are three things I can never remember, 1: um... 2: um... 3: um..."
-- Victor Borge
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
That is incorrect. The following two lines are exactly the same
No they are not. My post explains it in pretty much detail.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
*shrug* Try it yourself. 'string s = "abc"' has nothing to do with the copy constructor or the = operator.
--Mike--
"There are three things I can never remember, 1: um... 2: um... 3: um..."
-- Victor Borge
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
I did! Try the following (please bare with typos, I'm writing this without IDE support):
class A
{
public:
A(const char *)
{
}
private:
A(const A&);
};
int main()
{
A a="hello";
return 0;
} Under default settings, whis will compile fine and actually only A::A(const char*) is being invoked. However, if you set the /Za flag (disable MS proprietary extensions to C++), then an error pops up complaining that the copy ctor is not accessible and thus, by the rules of C++, optimizing it away is not legal. This is called elided copy constructor, and there's a paragraph in the standard dealing with the issue. Also Stroustrup in The C++ Programming Language, Special Edition states the sequence of calls for an expression of a form analogous to this in an example. If you're interested I could try to locate the exact paragraph for you.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
kilowatt wrote:
By calling:
string s1 = "the truth is out there";
you are first invoking the default constructor
That is incorrect. The following two lines are exactly the same:
string s1 = "the truth is out there";
string s1 ("the truth is out there"); They both call the one-parameter constructor.
--Mike--
"There are three things I can never remember, 1: um... 2: um... 3: um..."
-- Victor Borge
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
Not exactly. If you like C++ standard subtleties, please take a look at my post above.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
What message should my app handle when user shutdown/logoff the system?
thanx
|
|
|
|
|
The system will send a WM_QUERYENDSESSION message to all of the applications asking if it is OK to shutdown windows, if any one of them returns false, then windwos will quit shutting down.
After the system sends the WM_QUERYENDSESSION message, your app will receive a WM_ENDSESSION message indicating whether or not windows is actually going to shut down and your app should shut down.
|
|
|
|
|
Thanx ,
Where should i handle that ?
|
|
|
|
|
Handle it in your main window , WindowProc function, this is the window that it gets sent to.
|
|
|
|
|
|
Does anyone know if it is possible to login to a winNT box from over a network. I.E the other computer is at its login screen therefore standard screen sharing programs cannot be used as I think they require a server to be running on the unlogged in machine.
Thanks
Coremn
---------
I sig there for I am
(not an animal!!!)
|
|
|
|
|
Windows NT terminal server will do this, as will "VNC", provided you "install vnc as a service"
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I am trying to create an example using for_each to delete objects where they are stored in a container as pointers. I have this:
class pType
{
public:
pType::pType()
{
cout << "Constructor\n";
}
pType::~pType()
{
cout << "Destructor\n";
}
};
template <class T> void ptrErase(T * type)
{
delete type;
};
in main()
vector <pType *> vecpType;
for (i = 0;i < 20; ++i)
{
pType * pInt = new pType;
vecpType.push_back(pInt);
}
for_each(vecpType.begin(), vecpType.end(), ptrErase<pType>);
I get a linker error,
STL.obj : error LNK2001: unresolved external symbol "void __cdecl ptrErase(class pType *)" (?ptrErase@@YAXPAVpType@@@Z)
Debug/STL.exe : fatal error LNK1120: 1 unresolved externals
I am not as familiar with templated functions as I would like, could someone tell me what I am doing wrong pls ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Change this:
template<class T>
void ptrErase(T * type)
{
delete type;
};
to this:
template<class T>
struct ptrErase : public unary_function<T, void>
{
void operator() (T type)
{
delete type;
}
};
because the for_each function requires a function object rather than a simple function.
The operator() allows you to call the name of your object, just like it were a function call.
|
|
|
|
|
Thanks - I had contemplated that this might be the problem after posting, but I was hoping not for ease of readability ( it's a beginners tutorial after all ).
This works great - thanks again.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Some of the features in STL, and C++ for that matter, are convoluted, and I think that is what shys alot of people away from these features in the first place. This is a shame because learning some of these techniques can lead to very elegant solutions.
|
|
|
|