|
Pur those classes in separate files. Each class with one header file and one cpp file. In the header files, you can use forward declaration:
class Image;<br />
<br />
class Win<br />
{<br />
.....<br />
};
This will tell the compiler that the class Image exists and will be defined elsewhere. This works only because you are working with pointers and you don't use anything specific from the class (you just declare a pointer). This won't work if you use a class instance instead of a pointer.
Then in the cpp file of the Win class, you will need to include the header file of the Image class.
You'll need to do that for both classes.
|
|
|
|
|
Why does it work only when u use pointers?
|
|
|
|
|
it's not a matter of work, it's a matter of compilation.
the compiler won't let you compile a class or a function of even a variable declaration involving a Data Type it doesn't know.
but to let it know, a declaration (and not the full definition) is sufficient.
but if you declare without defining, the compilation will pass, but the linking will fail...
|
|
|
|
|
Because if you do something like that:
class Win<br />
{<br />
...<br />
...<br />
Image img;<br />
};
The compiler will need to know the size of the object in order to generate the Win class. Thus, the only way to know the size of the object is to know what's inside (thus, including the header file).
If you use pointers, the compiler always knows the size of a pointer and it doesn't need to know more.
|
|
|
|
|
as Cédric stated, you just have to declare the class before where it's used, and define it later (in a separate file preferably)...
|
|
|
|
|
Where does the scope of the below statement apply to?
#ifdef __cplusplus
extern "C"{
#endif
|
|
|
|
|
It says that everything between the brackets ( '{' ) will have a C linkage type. The difference between a standard C++ linkage is that in C, you don't have function overloading. The linker generates name to identify the different functions and for C, this generated name is the same as the function name. In C++, it is different: as you can have function overloading, having only the name of the function to identify it is not sufficient. The compiler will add some information (it is called name mangling) depending of the arguments of the function.
When you specify this, you force the compiler to generate the functions names as a C compiler would do. That means also that you won't be able to overload a function.
It is used mainly for DLL's: when you want to be able to load a function using GetProcAddress, the name of the function you will need to pass to GetProcAddress is the 'mangled name'. Thus, it is very difficult to use. If you specify that the function has a C linkage, the name that you will pass to the GetProcAddress function will be the function name only, which makes it far easier to use.
Hope it was clear...
|
|
|
|
|
Cedric Moonen wrote: the name of the function you will need to pass to GetProcAddress is the 'mangled name'
actually, it's the exported name, that means, the mangled name mainly, unless the DLL has a .def file with an EXPORTS block which redefines the exported symbols.
|
|
|
|
|
Yes right, I forgot about the DEF file.
|
|
|
|
|
I know the implication of it but what significance does it have over here
#ifdef __cplusplus
extern "C"{
#endif
It does not apply on any function neither does it have any group of functions. Does it mean the following expansion
__cplusplus int function(int a, int b) is equivalent to
extern "C"{ int function(int a, int b)
Am I missing something here?
|
|
|
|
|
tom groezer wrote: Does it mean the following expansion
__cplusplus int function(int a, int b) is equivalent to
extern "C"{ int function(int a, int b)
Am I missing something here?
actually, yes .
the directives block
#ifdef __cplusplus
extern "C" {
#endif have an equivalent block which closes the opened parenthesis, down the file :
#ifdef __cplusplus
}
#endif
it seems that you confused a bit about #ifdef and #define .
#define defines a macro, but #ifdef performs just a test to know if the macro tested has already been defined or not.
#ifdef __cplusplus
extern "C" {
#endif
int function(int a, int b);
#ifdef __cplusplus
}
#endif
in the sample above, it meens the following if __cplusplus is defined :
extern "C" {
int function(int a, int b);
} or only
int function(int a, int b); if not...
|
|
|
|
|
Hello,
I am implementing a utility through which i want to populate list of all devices attached with a system & then user can select any device & get information regarding device name,version ...
Please help me out as soon as possible.
Thanks & Regards
Pankaj
Regards,
Pankaj Sachdeva
|
|
|
|
|
pan_angel wrote: Please help me out as soon as possible.
I got to this as quickly as I could. Sorry for the inconvenience. Now, what exactly did you need help with?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Hi,
I am having trouble removing an object from a std::list.
I have got a Line object and a list structure in the form
std::list<line> lines;
and am trying to remove a particular Line object from the list by
Line * selectedLine;
// code to determine what line is selected
lines.remove(*selectedLine);
I get the error
c:\program files\microsoft visual studio 8\vc\include\list(908) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Line' (or there is no acceptable conversion)
c:\program files\microsoft platform sdk for windows server 2003 r2\include\guiddef.h(192): could be 'int operator ==(const GUID &,const GUID &)' [found using argument-dependent lookup]
while trying to match the argument list '(Line, const Line)'
c:\program files\microsoft visual studio 8\vc\include\list(898) : while compiling class template member function 'void std::list<_Ty>::remove(const _Ty &)'
with
[
_Ty=Line
]
c:\documents and settings\kevin\my documents\visual studio 2005\projects\sdl_001\sdl_001\main.h(391) : see reference to class template instantiation 'std::list<_Ty>' being compiled
with
[
_Ty=Line
]
I have tried searching google but all I can find is examples of how to remove integers and strings from lists
Any help would be appreciated
Kevin
|
|
|
|
|
I never used remove before but I suppose that you need to supply an ==operator for your Line class. Otherwise, the compiler cannot know if two Line objects are the same.
|
|
|
|
|
ah thats solved my problem. i thought the == operator was implicitly defined to check if two objects were equal
thanks
kevin
|
|
|
|
|
hi!i am trying to implement a code in c for cyclic reduction method.any one can help me (with an algorithm or the code itself)
|
|
|
|
|
hi!i am trying to implement a code in c for cyclic reduction (tridiagonal matrix).any one can help me (with an algorithm or the code itself)
|
|
|
|
|
where are you stuck ?
have you started anything, or are you just expecting us to pound out a working code ?
|
|
|
|
|
Hi All,
Pls let me know if there is any solution for this problem.
Im starting FTP uploading and at the same time HTTP downloading too for the same server which supports both ftp and http.
File is partially downloading at the receiver.Downloaded file size is less than the actual uploaded file.
Here problem is internetreadfile() is failing to read, once it does not receive data while file is uploading.
m_hHttpFile = HttpOpenRequest(m_hHttpConnection, "GET", FileToDownload, NULL, NULL, ppszAcceptTypes, INTERNET_FLAG_RELOAD |
INTERNET_FLAG_KEEP_CONNECTION, NULL);
if (m_hHttpFile == NULL)
{
return 0;
}
BOOL bSend = ::HttpSendRequest(m_hHttpFile, NULL, 0, NULL, 0);
if (!bSend)
{
AfxMessageBox(" Http download HttpSendRequest failed");
return 0;
}
TCHAR szStatusCode[32];
if (!HttpQueryInfo(m_hHttpFile, HTTP_QUERY_STATUS_CODE, szStatusCode, &dwInfoSize, NULL))
{
AfxMessageBox(" Http download HttpQueryInfo failed");
CString strMsg;
strMsg.Format("Error:%d", GetLastError());
//AfxMessageBox(strMsg);
return 0;
}
long nStatusCode = _ttol(szStatusCode);
if (nStatusCode != HTTP_STATUS_OK)
{
AfxMessageBox(" Http download server file not available ");
return 0;
}
DWORD dwBytesRead = 0;
char szReadBuf[TRANSFER_SIZE+1];
CFileException e;
m_FileToWrite.Open(LocalFile, CFile::modeCreate | CFile::modeWrite /*| CFile::shareDenyWrite*/);
double sum = 0;
do
{
if (!::InternetReadFile(m_hHttpFile, szReadBuf, TRANSFER_SIZE, &dwBytesRead))
{
AfxMessageBox("Http download InternetReadFile Failed");
return 0;
}
if(dwBytesRead>0)
{
TRY
{
m_FileToWrite.Write(szReadBuf, dwBytesRead);
}
CATCH(CFileException, e);
{
e->Delete();
return 0;
}
END_CATCH
}
sum += dwBytesRead;
}
while(sum!=filelength);
|
|
|
|
|
I'm not quite sure what the problem is...
"When I haven't finished uploading a file, downloading it fails part of the way through"
This sounds pretty straightforward to me! A little patience before downloading will probably cure your isssue.
Iain.
|
|
|
|
|
Hi
Thanks for ur response
Im able to start downloading the file using HTTP while the same file is being uploaded using FTP.
When ftp server permits to access that file while it is uploading, y cant we
download that file.
Actually we are able to download the file upto some extent. After that internetreadfile() is returning 0 bytes. After that its not reading the reamining data. internetreadfile()should wait for the requested amount of data. But its not doing so.
Its a bit urgent task for me. Awaiting for ur reply
|
|
|
|
|
Jyo2007 wrote: When ftp server permits to access that file while it is uploading, y cant we
download that file.
Why would you want to download a file that has not been fully uploaded yet?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Inorder to synchronize file upload and download it is quite obvious that u want to download the file which isnt uploaded completely.
When internet read file returns 0, close the handle to internet file, recall httpopenrequest() and httpsendfile()and then continue reading file from the location where previously the downloading has stopped(using internetsetfilepointer method).
|
|
|
|