Home > Archive > VC Language > May 2006 > Quick question!
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hello:
Can we pass a pointer to an object from one cpp file to another by using a
function call. Assuming the object was created and declared along with its
accessor methods in the first cpp file, but you need to manipulate the same
object in the second cpp file.
heres a quick example of the function call which calls a function
in the second cpp file:
==================cpp #1
#include "cpp2.h"
class components
{
public:
void SYS_innitz_FLAG_AllTrueInCase() {}
virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm) {}
protected:
};
static components cp;
SFC1(&cp); //Calling a function which exists in cpp #2
=======================
==================cpp2.h - header for cpp2
void SFC1(components *cp); //Function declaration
======================
==================cpp #2
void SFC1(components *cp) //Function implementation
{}
======================
When I do this I get the obvious errors of:
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19): error
C2065: 'components' : undeclared identifier
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19): error
C2065: 'cp' : undeclared identifier
It seems that all cpp files *must* have their own class definitions, and
associated implementations... right? I do beleive that I did post this
problem before at a much larger scale, however, there could be a wrinkle of
difference in this one. Basically, just double checking!
All welcome and appreciated for the feedback....
thanks!
--
Best regards
Robert
| |
| Abdo Haji-Ali 2006-05-28, 7:13 pm |
| "Robby" <Robby@discussions.microsoft.com> wrote in message
news:C8F5B8A4-D4D1-4A37-9D29-3588587F3428@microsoft.com...
> Hello:
>
> Can we pass a pointer to an object from one cpp file to another by using a
> function call. Assuming the object was created and declared along with its
> accessor methods in the first cpp file, but you need to manipulate the
same
> object in the second cpp file.
Yes, also you might want to have a look at the keyword 'extern' (Not for
this cas obviously)
[snip]
> ==================cpp2.h - header for cpp2
> void SFC1(components *cp); //Function declaration
> ======================
> ==================cpp #2
> void SFC1(components *cp) //Function implementation
> {}
> ======================
'components' is not declared in "cpp #2", so you should include cpp2.h in it
(as you did in "cpp #1")
> It seems that all cpp files *must* have their own class definitions,
If you mean declaration, then yes... If you do mean definition then look
below
> and associated implementations... right?
No, one implementations/definition is enough... It's the linker job to
*link* every declaration to the *unique* implementation
--
Abdo Haji-Ali
Programmer
In|Framez
| |
| David Wilkinson 2006-05-28, 7:13 pm |
| Robby wrote:
> Hello:
>
> Can we pass a pointer to an object from one cpp file to another by using a
> function call. Assuming the object was created and declared along with its
> accessor methods in the first cpp file, but you need to manipulate the same
> object in the second cpp file.
>
> heres a quick example of the function call which calls a function
> in the second cpp file:
>
> ==================cpp #1
> #include "cpp2.h"
> class components
> {
> public:
> void SYS_innitz_FLAG_AllTrueInCase() {}
> virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm) {}
> protected:
> };
>
> static components cp;
>
> SFC1(&cp); //Calling a function which exists in cpp #2
> =======================
>
> ==================cpp2.h - header for cpp2
> void SFC1(components *cp); //Function declaration
> ======================
> ==================cpp #2
> void SFC1(components *cp) //Function implementation
> {}
> ======================
>
> When I do this I get the obvious errors of:
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19): error
> C2065: 'components' : undeclared identifier
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19): error
> C2065: 'cp' : undeclared identifier
>
>
> It seems that all cpp files *must* have their own class definitions, and
> associated implementations... right? I do beleive that I did post this
> problem before at a much larger scale, however, there could be a wrinkle of
> difference in this one. Basically, just double checking!
>
> All welcome and appreciated for the feedback....
>
> thanks!
>
Robby:
This is hopelessly .
1. Class definitions go in .h files; your components class seems to be
defined in a .cpp file. Therefore it cannot be used in any other .cpp file.
2. Pointers are passed from one function (or method) to another, not
from one file to another.
3. What is the statement
SFC1(&cp);
? It does not seem to be in any function.
4. The error messages you show are in a file "SFC_1.h", but you do not
show us this file.
5. I sense that what you are trying to do may require a technique called
forward declaration. But I am not quite sure what you are trying to do.
David Wilkinson
| |
| Abdo Haji-Ali 2006-05-28, 7:13 pm |
|
"Abdo Haji-Ali" <ahali@inframez.org_use_com_instead> wrote in message
news:OWJQZgngGHA.2040@TK2MSFTNGP03.phx.gbl...
> "Robby" <Robby@discussions.microsoft.com> wrote in message
> news:C8F5B8A4-D4D1-4A37-9D29-3588587F3428@microsoft.com...
a[color=darkred]
its[color=darkred]
> same
> Yes, also you might want to have a look at the keyword 'extern' (Not for
> this cas obviously)
>
> [snip]
>
> 'components' is not declared in "cpp #2", so you should include cpp2.h in
it
> (as you did in "cpp #1")
Duh!!! I've just noticed that 'components' is declared in "cpp #2", not in
cpp2.h... So in order to make this work you'll have to move the declaration
to cpp2.h (Or any other header file) then include it in both cpp files
--
Abdo Haji-Ali
Programmer
In|Framez
| |
| Abdo Haji-Ali 2006-05-28, 7:13 pm |
| "Abdo Haji-Ali" <ahali@inframez.org_use_com_instead> wrote in message
news:#R2WV3ngGHA.3996@TK2MSFTNGP03.phx.gbl...
>
> "Abdo Haji-Ali" <ahali@inframez.org_use_com_instead> wrote in message
> news:OWJQZgngGHA.2040@TK2MSFTNGP03.phx.gbl...
using[color=darkred]
> a
> its
in[color=darkred]
> it
> Duh!!! I've just noticed that 'components' is declared in "cpp #2"
I meant "cpp #1"... God I really should get some sleep :)
--
Abdo Haji-Ali
Programmer
In|Framez
| |
|
| Hi David and Abdo,
no no no! I know that class def's go in .h files, I was just trying to
shorten the example...
However, I am trying to move the functionality done with classes declared in
one cpp file to another cpp file... and its resulting in a big mess, 72
errors or 104 erros.... and so on!
Let me get back to you guys with the full explanation of what I am trying to
do. However I also want to make sure that this post gets to the news groups
because I am trying this from Outlook news reader!
I will get back soon... Thankyou!
"Robby" <Robby@discussions.microsoft.com> wrote in message
news:C8F5B8A4-D4D1-4A37-9D29-3588587F3428@microsoft.com...
> Hello:
>
> Can we pass a pointer to an object from one cpp file to another by using a
> function call. Assuming the object was created and declared along with its
> accessor methods in the first cpp file, but you need to manipulate the
> same
> object in the second cpp file.
>
> heres a quick example of the function call which calls a function
> in the second cpp file:
>
> ==================cpp #1
> #include "cpp2.h"
> class components
> {
> public:
> void SYS_innitz_FLAG_AllTrueInCase() {}
> virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm) {}
> protected:
> };
>
> static components cp;
>
> SFC1(&cp); //Calling a function which exists in cpp #2
> =======================
>
> ==================cpp2.h - header for cpp2
> void SFC1(components *cp); //Function declaration
> ======================
> ==================cpp #2
> void SFC1(components *cp) //Function implementation
> {}
> ======================
>
> When I do this I get the obvious errors of:
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19):
> error
> C2065: 'components' : undeclared identifier
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19):
> error
> C2065: 'cp' : undeclared identifier
>
>
> It seems that all cpp files *must* have their own class definitions, and
> associated implementations... right? I do beleive that I did post this
> problem before at a much larger scale, however, there could be a wrinkle
> of
> difference in this one. Basically, just double checking!
>
> All welcome and appreciated for the feedback....
>
> thanks!
>
> --
> Best regards
> Robert
>
| |
|
| Hi David and Abdo....its just one of those days !
OKAY,
Right now this is the way I have it! Lets forget about the classes that derive from components for now.
Just the class definition is show!
Here is the code:
======================================Wn
dProc.h
class components
{
public:
components(){}
components(int Flag);
virtual ~components() {}
virtual void SYS_innitz_FLAG_AllTrueInCase();
virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm);
virtual int SYS_get_FLAG_AllTrueInCase()const;
virtual bool SYS_Validate_FLAG_AllTrueInCase();
static int FLAG_AllTrueInCase;
protected:
};
========================================
=======
======================================Wn
dProc.cpp
#include "WndProc.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
PARAM wParam, LPARAM lParam)
{
static components cp(0);
....other code...
case WM_TIMER:
cp.SYS_set_SFCC(true,1);
.... other code...
}
========================================
=======
What I am trying to do is to take the calling of methods in the Timer handler ex:
cp.SYS_set_SFCC(true,1);
and put them in another cpp file called "SFC_1.cpp"
So here is the whole sample again:
======================================Wn
dProc.h
class components
{
public:
components(){}
components(int Flag);
virtual ~components() {}
virtual void SYS_innitz_FLAG_AllTrueInCase();
virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm);
virtual int SYS_get_FLAG_AllTrueInCase()const;
virtual bool SYS_Validate_FLAG_AllTrueInCase();
static int FLAG_AllTrueInCase;
protected:
};
=======================================
========================================
WndProc.cpp
#include "WndProc.h"
#include "SFC_1.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
PARAM wParam, LPARAM lParam)
{
static components cp(0);
....other code...
case WM_TIMER:
SFC1(&cp);
.... other code...
}
========================================
============
========================================
======SFC_1.h
bool SFC1(components &cp);
========================================
============
========================================
====SFC_1.cpp
#include "SFC_1.h"
#include "WndProc.h"
bool SFC1(compopnents *cp)
{
//so I can do stuff like this....
cp->SYS_set_SFCC(true,1);
}
========================================
==============
The errors might not be exactly the same as my previous post due to some includes I have added, however here are the errors!
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(16): error C2065: 'components' : undeclared identifier
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(16): error C2065: 'cp' : undeclared identifier
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(16): fatal error C1903: unable to recover from previous error(s); stopping compilation
Anyways, Please get back!
appreciated!
Regards Roberto
"Robby" <Robby@discussions.microsoft.com> wrote in message news:C8F5B8A4-D4D1-4A37-9D29-3588587F3428@microsoft.com...
> Hello:
>
> Can we pass a pointer to an object from one cpp file to another by using a
> function call. Assuming the object was created and declared along with its
> accessor methods in the first cpp file, but you need to manipulate the same
> object in the second cpp file.
>
> heres a quick example of the function call which calls a function
> in the second cpp file:
>
> ==================cpp #1
> #include "cpp2.h"
> class components
> {
> public:
> void SYS_innitz_FLAG_AllTrueInCase() {}
> virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm) {}
> protected:
> };
>
> static components cp;
>
> SFC1(&cp); //Calling a function which exists in cpp #2
> =======================
>
> ==================cpp2.h - header for cpp2
> void SFC1(components *cp); //Function declaration
> ======================
> ==================cpp #2
> void SFC1(components *cp) //Function implementation
> {}
> ======================
>
> When I do this I get the obvious errors of:
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19): error
> C2065: 'components' : undeclared identifier
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(19): error
> C2065: 'cp' : undeclared identifier
>
>
> It seems that all cpp files *must* have their own class definitions, and
> associated implementations... right? I do beleive that I did post this
> problem before at a much larger scale, however, there could be a wrinkle of
> difference in this one. Basically, just double checking!
>
> All welcome and appreciated for the feedback....
>
> thanks!
>
> --
> Best regards
> Robert
>
| |
| Abdo Haji-Ali 2006-05-28, 7:13 pm |
| "Robby" <logicom@sympatico.ca> wrote in message
news:Aaneg.159$EF1.19759@news20.bellglobal.com...
> ========================================
====SFC_1.cpp
> #include "SFC_1.h"
> #include "WndProc.h"
Here's your problem. After the preprocessing stage this cpp would look like
this:
bool SFC1(components &cp); // From SFC_1.h
class components // From WndProc.h
{
// Reset of class declaration
};
As you can see: 'components' is used in the function declaration before the
class is declared, so you should either:
1. Reverse the #include directives so that WndProc.h is included before
SFC_1.h
2. Use forward-reference *before* the #include of SFC_1.h
Hope that helped,
--
Abdo Haji-Ali
Programmer
In|Framez
| |
| David Wilkinson 2006-05-28, 7:13 pm |
| Robby wrote:
[color=darkred]
> Hi David and Abdo....its just one of those days !
>
> OKAY,
>
> Right now this is the way I have it! Lets forget about the classes that derive from components for now.
> Just the class definition is show!
>
> Here is the code:
>
> ======================================Wn
dProc.h
> class components
> {
> public:
> components(){}
> components(int Flag);
> virtual ~components() {}
> virtual void SYS_innitz_FLAG_AllTrueInCase();
> virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm);
> virtual int SYS_get_FLAG_AllTrueInCase()const;
> virtual bool SYS_Validate_FLAG_AllTrueInCase();
> static int FLAG_AllTrueInCase;
> protected:
> };
> ========================================
=======
>
> ======================================Wn
dProc.cpp
> #include "WndProc.h"
>
> LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
> PARAM wParam, LPARAM lParam)
> {
> static components cp(0);
>
> ...other code...
>
> case WM_TIMER:
> cp.SYS_set_SFCC(true,1);
>
> ... other code...
> }
> ========================================
=======
>
> What I am trying to do is to take the calling of methods in the Timer handler ex:
>
> cp.SYS_set_SFCC(true,1);
>
> and put them in another cpp file called "SFC_1.cpp"
>
> So here is the whole sample again:
>
> ======================================Wn
dProc.h
> class components
> {
> public:
> components(){}
> components(int Flag);
> virtual ~components() {}
> virtual void SYS_innitz_FLAG_AllTrueInCase();
> virtual void SYS_set_SFCC(bool bCondTrue,int AmtOfComm);
> virtual int SYS_get_FLAG_AllTrueInCase()const;
> virtual bool SYS_Validate_FLAG_AllTrueInCase();
> static int FLAG_AllTrueInCase;
> protected:
> };
> =======================================
>
> ========================================
WndProc.cpp
> #include "WndProc.h"
> #include "SFC_1.h"
>
> LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
> PARAM wParam, LPARAM lParam)
> {
> static components cp(0);
>
> ...other code...
>
> case WM_TIMER:
> SFC1(&cp);
>
> ... other code...
> }
> ========================================
============
>
>
> ========================================
======SFC_1.h
> bool SFC1(components &cp);
> ========================================
============
>
>
> ========================================
====SFC_1.cpp
> #include "SFC_1.h"
> #include "WndProc.h"
>
> bool SFC1(compopnents *cp)
> {
>
> //so I can do stuff like this....
> cp->SYS_set_SFCC(true,1);
> }
> ========================================
==============
>
> The errors might not be exactly the same as my previous post due to some includes I have added, however here are the errors!
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(16): error C2065: 'components' : undeclared identifier
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(16): error C2065: 'cp' : undeclared identifier
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\SFC_1.h(16): fatal error C1903: unable to recover from previous error(s); stopping compilation
>
>
> Anyways, Please get back!
> appreciated!
>
> Regards Roberto
>
>
> "Robby" <Robby@discussions.microsoft.com> wrote in message news:C8F5B8A4-D4D1-4A37-9D29-3588587F3428@microsoft.com...
>
>
Robby:
As Abdo has pointed out, the problem is that components is not defined
or declared in SFC_1.h . While this can be fixed bt changing the order
of includes in SFC_1.cpp, much the better way is a forward declaration:
// ========================================
======SFC_1.h
class components; // forward declaration
bool SFC1(components &cp);
// ========================================
============
I don't think this is causing you a problem here, but you might also
read about include guards (or pragma once).
David Wilkinson
| |
|
| Thankyou Abdo!
I am having a very bad day today!
Now that I have fixed the bug that you found, I got rid of the 3 errors,
however, now.... if I remove completely the SFC1.h and the SFC1.cpp and dont
include the SFC1.h anywhere,
everything compiles successfully. BUT, if I put in the SFC1.h and the
SFC1.cpp in ,my project and include the SFC1.h and WndProc.h files as we
said, I get 22 build erros which have nothing to do with the SFC1 file....
weird errors like this:
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(138):
error C2061: syntax error : identifier 'HWND'
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(168):
error C2061: syntax error : identifier 'HWND'
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(434):
error C2065: 'HWND' : undeclared identifier
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(434):
error C2146: syntax error : missing ')' before identifier 'hwnd'
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(434):
error C2761: 'void A_TMR::setTimer(void)' : member function redeclaration
not allowed
c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(434):
error C2059: syntax error : ')'
and the errors go on....
And my whole program is much too large to post it....
How could these errors come when I simply add in functionality for a new
..cpp and .h files with one function in it?
any suggestions? any at all!
I think I am going to go to bed!
Thanks
Robert
"Abdo Haji-Ali" <ahali@inframez.org_use_com_instead> wrote in message
news:%23waGjSpgGHA.1264@TK2MSFTNGP05.phx.gbl...
> "Robby" <logicom@sympatico.ca> wrote in message
> news:Aaneg.159$EF1.19759@news20.bellglobal.com...
>
> Here's your problem. After the preprocessing stage this cpp would look
> like
> this:
>
> bool SFC1(components &cp); // From SFC_1.h
> class components // From WndProc.h
> {
> // Reset of class declaration
> };
>
> As you can see: 'components' is used in the function declaration before
> the
> class is declared, so you should either:
> 1. Reverse the #include directives so that WndProc.h is included before
> SFC_1.h
> 2. Use forward-reference *before* the #include of SFC_1.h
>
> Hope that helped,
> --
> Abdo Haji-Ali
> Programmer
> In|Framez
>
>
| |
| Igor Tandetnik 2006-05-28, 7:13 pm |
| "Robby" <logicom@sympatico.ca> wrote in message
news:Aaneg.159$EF1.19759@news20.bellglobal.com
> SFC1(&cp);
This calls a function SFC1 with a paramter of type components*, that is,
pointer to components.
> bool SFC1(components &cp);
This declares a function named SFC1 taking a parameter of type
components&, that is, reference to components. Note that this is a
different function from the one that's actually called.
SFC1(components*) is not declared anywhere.
> bool SFC1(compopnents *cp)
Finally, you implement SFC1(components*) which matches the function
being called, but not the one being declared.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
| |
|
| Hey David!
You did it again! :-)
*IT COMPILES WITHOUT ANY ARRORS*
So, I will try this new "Forward declaration" stuff you just tought me with
all the rest of my other pointers to objects that I want to pass to this
function. I know that Abdo mentioned it in his post as:
2. Use forward-reference *before* the #include of SFC_1.h
however this is new to me and I didn't know how to apply the syntax? However
thankyou also Abdo!
One thing though, If I do use:
class components; // forward declaration
in my SFC1.h file, what happens to all the other objects that derive from
it.... are they automatically declared also, or must I do this for all the
others too?
And David, one last question............ As a few posts back you talked
about me using the stack instead of using new which would otherwise make me
look like a Java programmer :) remember? Well.... while we are on the
subject, one of my buddies has an IT company and he says that everyone is
going on JAVA and that C++/VC++ will eventually not be very popular anymore!
This discouraged me, but I know that I must take his opinion lightly since
he is no major beer in the IT world. Anyways, I and I am sure of it for many
others, put alot of time in a language like C... what is your opinion on the
future existance of C++ and VC++?
On that note, My freind! I must say.... Its been 12 hours I am in front of
this screen! And now I must stop!
I thankyou guys very much......
Have a good w end ...or whatever is left of it!
Very kind Regards
Roberto
"David Wilkinson" <no-reply@effisols.com> wrote in message
news:%23hxg2AqgGHA.3652@TK2MSFTNGP02.phx.gbl...
> Robby wrote:
>
>
> Robby:
>
> As Abdo has pointed out, the problem is that components is not defined or
> declared in SFC_1.h . While this can be fixed bt changing the order of
> includes in SFC_1.cpp, much the better way is a forward declaration:
>
> // ========================================
======SFC_1.h
>
> class components; // forward declaration
> bool SFC1(components &cp);
>
> // ========================================
============
>
> I don't think this is causing you a problem here, but you might also read
> about include guards (or pragma once).
>
> David Wilkinson
| |
|
| Hello Igor!
How do you do?
Thankyou for your input, it is appreciated!
I still do get kind of with correctly phrasing stuff like this....
I will read it over.
Thanks
Regards
Robert
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:eislsMqgGHA.2188@TK2MSFTNGP04.phx.gbl...
> "Robby" <logicom@sympatico.ca> wrote in message
> news:Aaneg.159$EF1.19759@news20.bellglobal.com
>
> This calls a function SFC1 with a paramter of type components*, that is,
> pointer to components.
>
>
> This declares a function named SFC1 taking a parameter of type
> components&, that is, reference to components. Note that this is a
> different function from the one that's actually called. SFC1(components*)
> is not declared anywhere.
>
>
> Finally, you implement SFC1(components*) which matches the function being
> called, but not the one being declared.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
| |
| David Wilkinson 2006-05-29, 4:19 am |
| Robby wrote:
> Hey David!
>
> You did it again! :-)
>
> *IT COMPILES WITHOUT ANY ARRORS*
>
>
> So, I will try this new "Forward declaration" stuff you just tought me with
> all the rest of my other pointers to objects that I want to pass to this
> function. I know that Abdo mentioned it in his post as:
>
> 2. Use forward-reference *before* the #include of SFC_1.h
>
> however this is new to me and I didn't know how to apply the syntax? However
> thankyou also Abdo!
>
> One thing though, If I do use:
>
> class components; // forward declaration
>
> in my SFC1.h file, what happens to all the other objects that derive from
> it.... are they automatically declared also, or must I do this for all the
> others too?
>
> And David, one last question............ As a few posts back you talked
> about me using the stack instead of using new which would otherwise make me
> look like a Java programmer :) remember? Well.... while we are on the
> subject, one of my buddies has an IT company and he says that everyone is
> going on JAVA and that C++/VC++ will eventually not be very popular anymore!
> This discouraged me, but I know that I must take his opinion lightly since
> he is no major beer in the IT world. Anyways, I and I am sure of it for many
> others, put alot of time in a language like C... what is your opinion on the
> future existance of C++ and VC++?
>
[snip]
Robby:
When you forward declare, for example
class components; // forward declaration
you are just telling the compiler that there is a class called
components. If the compiler needs to recognize the names of other
classes derived from components, then you must forward declare those also.
A good rule to follow with headers is: Every header should compile by
itself (i.e. when included in an empty .cpp file). Forward declaration
is often sufficient to achieve this.
Just my opinion, but I would say that today .NET is a much greater
threat to traditional C/C++ than Java.
David Wilkinson
| |
| David Wilkinson 2006-05-29, 4:19 am |
| Robby wrote:
> Thankyou Abdo!
>
> I am having a very bad day today!
>
> Now that I have fixed the bug that you found, I got rid of the 3 errors,
> however, now.... if I remove completely the SFC1.h and the SFC1.cpp and dont
> include the SFC1.h anywhere,
> everything compiles successfully. BUT, if I put in the SFC1.h and the
> SFC1.cpp in ,my project and include the SFC1.h and WndProc.h files as we
> said, I get 22 build erros which have nothing to do with the SFC1 file....
> weird errors like this:
>
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(138):
> error C2061: syntax error : identifier 'HWND'
> c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\M
Y_APPS_LAB\XPPLC\WndProc.h(168):
> error C2061: syntax error : identifier 'HWND'
[snip]
Robby:
When you see something like the above, it is very likely that you have
not included windows.h, or have not included it in the right place. In
fact, I do not see an include of windows.h in the code you showed.
David Wilkinson
| |
|
| Thanks David for your input!
Thankyou to all!
Later!
Best regards
Roberto
"David Wilkinson" <no-reply@effisols.com> wrote in message
news:%23$WTtcwgGHA.2208@TK2MSFTNGP05.phx.gbl...
> Robby wrote:
>
>
> [snip]
>
> Robby:
>
> When you forward declare, for example
>
> class components; // forward declaration
>
> you are just telling the compiler that there is a class called components.
> If the compiler needs to recognize the names of other classes derived from
> components, then you must forward declare those also.
>
> A good rule to follow with headers is: Every header should compile by
> itself (i.e. when included in an empty .cpp file). Forward declaration is
> often sufficient to achieve this.
>
> Just my opinion, but I would say that today .NET is a much greater threat
> to traditional C/C++ than Java.
>
> David Wilkinson
>
>
>
>
| |
| Abdo Haji-Ali 2006-05-30, 8:08 am |
| "Robby" <logicom@sympatico.ca> wrote in message
news:Eppeg.202$EF1.25360@news20.bellglobal.com...
> Hey David!
>
> You did it again! :-)
>
> *IT COMPILES WITHOUT ANY ARRORS*
>
>
> So, I will try this new "Forward declaration" stuff you just tought me
with
> all the rest of my other pointers to objects that I want to pass to this
> function. I know that Abdo mentioned it in his post as:
>
> 2. Use forward-reference *before* the #include of SFC_1.h
>
> however this is new to me and I didn't know how to apply the syntax?
However
> thankyou also Abdo!
>
Actually I meant forward declaration (Guess all that .NET programming is
affecting me :)
--
Abdo Haji-Ali
Programmer
In|Framez
|
|
|
|
|