|
bloodwinner wrote: again, I am still confusing...
is that
int i:
it will be ready when you start use it
static int i:
it will be ready long before you use it
So what's the use of the latter occasion? Since I don't use it, why should I care when it is created.
Imagine a function that animates something on the screen. Each call to the function updates the phase of the animation by using a counter to determine what's displayed. To this end you need an int as the counter and you declare it inside the function rather than having your primary program pass the counter to the function. If you declare the int as non-static but you increment the int each time you enter the function the value of the int goes away because the variable was created on the stack when the function began and it was removed when the function ended.
If you declare the int as static, whatever value it had on exit from the function is the value it will have when you call the function again because the variable was created before the program began execution and will not be destroyed until the program ends.
Lilith
|
|
|
|
|
A Static variable has a global scope. So if the value of static variable changed, that change will occur where ever the static variable is used.
Akkott
|
|
|
|
|
|
Hi,
Can any tell me the internal working of the try/catch block in C++.
Thanks.
|
|
|
|
|
|
when i run MFC and MySQL
By Victor M. Valenzuela.
MFC classes to fill ComoBoxes & ListBoxes with MySQL data.
then it gives following error, i am not able to trace out this error,
as far as i am concerened here two files are conflicting.
how to avoid this conflicting problem.
i am solving this problem from last 4 days, but i didn't found any clue about this problem.
please tell me the solution i am very needy.
Linking...
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char=""> > & __cdecl std::operator<<(class std::basic_ostream<char,struct std::char_traits<char=""> > &,char const *)" (??6std@@YAAAV?$basic_ostream@DU?$cha
r_traits@D@std@@@0@AAV10@PBD@Z) already defined in mysql++.lib(manip.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: virtual __thiscall std::basic_ios<char,struct std::char_traits<char=""> >::~basic_ios<char,struct std::char_traits<char=""> >(void)" (??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ) already defined
in mysql++.lib(sql_query.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: virtual __thiscall std::basic_streambuf<char,struct std::char_traits<char=""> >::~basic_streambuf<char,struct std::char_traits<char=""> >(void)" (??1?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAE@XZ
) already defined in mysql++.lib(sql_query.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >(void)" (??1?$basic_strin
g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in mysql++.lib(connection.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >(class std::basic_string<c
har,struct std::char_traits<char="">,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in mysql++.lib(connection.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >(class std::allocator<char
> const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV?$allocator@D@1@@Z) already defined in mysql++.lib(connection.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: virtual __thiscall std::basic_iostream<char,struct std::char_traits<char=""> >::~basic_iostream<char,struct std::char_traits<char=""> >(void)" (??1?$basic_iostream@DU?$char_traits@D@std@@@std@@UAE@XZ) a
lready defined in mysql++.lib(sql_query.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_iostream<char,struct std::char_traits<char=""> >::basic_iostream<char,struct std::char_traits<char=""> >(class std::basic_streambuf<char,struct std::char_traits<char=""> > *)" (??0?$b
asic_iostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@@Z) already defined in mysql++.lib(sql_query.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Q
BEPBDXZ) already defined in mysql++.lib(connection.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: char & __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::operator[](unsigned int)" (??A?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEA
ADI@Z) already defined in mysql++.lib(field_names.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in mysql++.lib(sql_query.obj)
libcp.lib(iostream.obj) : error LNK2005: "public: __thiscall std::ios_base::Init::Init(void)" (??0Init@ios_base@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(iostream.obj) : error LNK2005: "public: __thiscall std::ios_base::Init::~Init(void)" (??1Init@ios_base@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(iostream.obj) : error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char=""> >::basic_ostream<char,struct std::char_traits<char=""> >(class std::basic_streambuf<char,struct std::char_traits<char=""> > *,bool,bool)" (?
?0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N1@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(locale.obj) : error LNK2005: "public: __thiscall std::_Locinfo::_Locinfo(char const *)" (??0_Locinfo@std@@QAE@PBD@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(locale.obj) : error LNK2005: "public: __thiscall std::_Locinfo::~_Locinfo(void)" (??1_Locinfo@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(locale0.obj) : error LNK2005: "public: class std::locale::facet const * __thiscall std::locale::_Getfacet(unsigned int,bool)const " (?_Getfacet@locale@std@@QBEPBVfacet@12@I_N@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(locale0.obj) : error LNK2005: "public: bool __thiscall std::locale::_Iscloc(void)const " (?_Iscloc@locale@std@@QBE_NXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" (?_Init@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(ios.obj) : error LNK2005: "public: void __thiscall std::ios_base::clear(int,bool)" (?clear@ios_base@std@@QAEXH_N@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(ios.obj) : error LNK2005: "public: virtual __thiscall std::ios_base::~ios_base(void)" (??1ios_base@std@@UAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcp.lib(ios.obj) : error LNK2005: "protected: void __thiscall std::ios_base::_Init(void)" (?_Init@ios_base@std@@IAEXXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
LIBC.lib(strtol.obj) : error LNK2005: _strtol already defined in msvcrtd.lib(MSVCRTD.dll)
LIBC.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBC.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(atox.obj) : error LNK2005: _atoi already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in LIBC.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/DlgMySql.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
mee
|
|
|
|
|
you are mixing C/C++ runtime libraries.
make sure all libraries that link into your final EXE are using the same C/C++ RTL . check this in Project/Settings/General (Microsoft Foundation Classes) and Project/Settings/ C/C++ / Code Generation / Use Runtime library.
|
|
|
|
|
CString Convert to LPCTSTR
i write DLL file,it is static dll
i want CString type Convert to LPCTSTR
but error
Code:
<<<<<<<<<<<dll file="">>>>>>>>>
<<<<<<<a.h>>>>>>>
class AFX_NOVTABLE dll
{
public:
__declspec(dllexport) LPCTSTR Fun();
};
<<<<<<<a.cpp>>>>>>
LPCTSTR dll::Fun()
{
CString Rxg=_T("rxg");
LPCTSTR lpszStr=Rxg.GetBuffer();
return lpszStr;
}
<<<<<<<<exe>>>>>>>>>
#pragma comment(lib,"dll.lib")
#include "A.h"
..................
dll d;
LPCTSTR b=d.Fun();
error,why
thank
|
|
|
|
|
rxgmoral wrote: error,
what it states ?
|
|
|
|
|
CString has an operator for casting to LPCTSTR. There is no need to write code to do it, it is already done for you.
On top of all that, you are creating a memory leak while trying to duplicate code that is written for you.
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
|
|
|
|
|
rxgmoral wrote: LPCTSTR dll::Fun()
{
CString Rxg=_T("rxg");
LPCTSTR lpszStr=Rxg.GetBuffer();
return lpszStr;
}
you return a local pointer...
|
|
|
|
|
rxgmoral wrote: LPCTSTR lpszStr=Rxg.GetBuffer();
If you aren't going to be modifying the contents of Rxg , there's no need to call GetBuffer() .
rxgmoral wrote: error,why
Don't know.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
1. First, you have a CString which is only temporary. When Fun() ends, the CString object will be destructed.
2. As has been pointed out, GetBuffer() isn't needed, since there's a perfectly good cast operator for LPCTSTR.
3. As written, the temporary CString (Rxg) will get locked by GetBuffer(). This will no doubt cause problems when the temporary is destructed, since the CString data is now locked.
To get string data back from the DLL function, you could pass in a destination buffer and size as parameters, and after checking size, you can then fill in the string. To retain the semantics of Fun(), have it return the address of the destination buffer (although the parameter should be LPTSTR, not LPCTSTR).
Steve S
Developer for hire
|
|
|
|
|
rxgmoral wrote: LPCTSTR dll::Fun()
{
CString Rxg=_T("rxg");
LPCTSTR lpszStr=Rxg.GetBuffer();
return lpszStr;
}
better you make memory in heap before sending it outside of function.. though getbuffer create the memory in heap.. but it need subsequent call of releasebuffer for releasing the memory.. which is rather difficult from out side better would be....
LPTSTR lpszStr=new TCHAR[Rxg.GetLength()+1];
lstrcpy(lpszStr,Rxg);
return lpszStr;
"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
Support CRY- Child Relief and You
|
|
|
|
|
if you want to use GetBuffer then call ReleaseBuffer
|
|
|
|
|
|
Yes, it's called a debugger
|
|
|
|
|
If you are the one throwing it, and you are using Microsoft's compiler, you can use the __FILE__ and __LINE__ directives as a part of your exception message.
class custom_exception : public exception
{
public:
custom_exception(const string& file, const string& line, const string& msg)
{
_Msg = file;
_Msg += ":";
_Msg += line;
_Msg += "::";
_Msg += msg;
}
string getMessage() const
{
return _Msg;
}
private:
string _Msg;
};
void MyFunction() throw(...)
{
throw custom_exception(__FILE__, __LINE__, "Something went wrong here!");
}
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
|
|
|
|
|
KKumarTG wrote: [Message Deleted]
Message Deletion is sin here!
"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
Support CRY- Child Relief and You
|
|
|
|
|
|
how can I convert a matlab file to c++??????
please help me!!!!!!!!;)
|
|
|
|
|
I am not aware of any m2c converter, but this CP article shows you can build a DLL from a m-file and then call it in C/C++ applications.
Best,
Jun
|
|
|
|
|
Hi,
is it possible to share OpenGL Displaylists in MDI Applications? I would like to do the following:
1) compile some displaylists
2) Make some CView CDocument Objects
3) Use all or some of the displaylists in different CView`s
Many Thanks
Olaf
|
|
|
|
|
I believe display lists are limited to an OpenGL rendering context. Although you can share rendering contexts across windows (by changing the device context), they must all share the same pixel format. (found in OpenGL Superbible pg. 658)
hRC = wglCreateContext(hDC); //initially create rendering context
wglMakeCurrent(hDC,hRC); //change to a different hDC, keeping the original hRC
Can't say I have actually done this...
|
|
|
|
|
wglShareLists
...cmk
Save the whales - collect the whole set
|
|
|
|
|