Include h files

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 122
Reputation: Liszt is an unknown quantity at this point 
Solved Threads: 6
Liszt Liszt is offline Offline
Junior Poster

Include h files

 
0
  #1
Nov 9th, 2008
Why does I encounter a compileerror when doing this.

Compile error says.
'Form3' : undeclared identifier
'Form4' : undeclared identifier

Inside of Form4.h:
  1. #include "Form3.h"
  2.  
  3. Form3 ^form3 = gcnew Form3;
  4. form3->ShowDialog();


Inside of Form3.h:
  1. #include "Form4.h"
  2.  
  3. Form4 ^form4 = gcnew Form4;
  4. form4->ShowDialog();
Last edited by Liszt; Nov 9th, 2008 at 5:48 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Include h files

 
0
  #2
Nov 9th, 2008
because you have recursive includes -- form3.h includes form4.h which includes form3.h ...

Not a good idea, as you have found out.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 122
Reputation: Liszt is an unknown quantity at this point 
Solved Threads: 6
Liszt Liszt is offline Offline
Junior Poster

Re: Include h files

 
0
  #3
Nov 9th, 2008
That shouldn´t be a good idéa so I get over many examples how to go around this problem.
In somehow I have to use any form of a forward declaration. This is my code so far.

Still I have the compilerror for:
'Form22' : no appropriate default constructor available

I have followed an example but are not defenetive of what is going on in this code and would greatly appreciate any guidance in the code in order to really understand it.


Inside Form3.h
  1. ref class Form4;
  2. ref class Form3
  3. {
  4. public:
  5. Form4 ^SomeMethodA();
  6. };

Inside Form3.cpp
  1. #include "stdafx.h"
  2. #include "Form3.h"
  3. #include "Form4.h"
  4.  
  5. Form4 ^Form3::SomeMethodA()
  6. {
  7. return gcnew Form4;
  8. }


Inside Form4.h
  1. ref class Form3;
  2. ref class Form4
  3. {
  4. public:
  5. Form3 ^SomeMethodB();
  6. };


Inside Form4.cpp
  1. #include "stdafx.h"
  2. #include "Form3.h"
  3. #include "Form4.h"
  4.  
  5. Form3 ^Form4::SomeMethodB() //SomeMethodB is not found as a member ?
  6. {
  7. return gcnew Form4;
  8. }


Originally Posted by Ancient Dragon View Post
because you have recursive includes -- form3.h includes form4.h which includes form3.h ...

Not a good idea, as you have found out.
Last edited by Liszt; Nov 9th, 2008 at 8:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Include h files

 
0
  #4
Nov 9th, 2008
I think in the *.cpp implementation files you need to add using namespace <namespace name>; . That made it work in my test program.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 122
Reputation: Liszt is an unknown quantity at this point 
Solved Threads: 6
Liszt Liszt is offline Offline
Junior Poster

Re: Include h files

 
0
  #5
Nov 9th, 2008
Okay, thank you. In your testprogram, did you try to open eachothers forms
or just compiling the code without the code that open forms ?

I could wonder what this meen.
using namespace <namespace name>;
If I use that line in the *.cpp files, I will have the errors:
1>.\Form3.cpp(5) : error C2059: syntax error : '<'
1>.\Form4.cpp(6) : error C2059: syntax error : '<'

If I dont use the using namespace <namespace name>; line and dont use the codes that will open eachothers forms, it will compiles fine. I dont know what this leaves the problem or solution.



Originally Posted by Ancient Dragon View Post
I think in the *.cpp implementation files you need to add using namespace <namespace name>; . That made it work in my test program.
Last edited by Liszt; Nov 9th, 2008 at 9:16 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Include h files

 
0
  #6
Nov 9th, 2008
Replace the "<namespace name>" with the namespace used in your programs. You can find this in the *.h file, for example
#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

#include "Form1.h"

namespace testform {

Yours will be different than mine -- the VC++ 2008 compiler generates the namespace name based on the project name when you created the project.

So I added this line: using namespace testform;
Last edited by Ancient Dragon; Nov 9th, 2008 at 10:18 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 122
Reputation: Liszt is an unknown quantity at this point 
Solved Threads: 6
Liszt Liszt is offline Offline
Junior Poster

Re: Include h files

 
0
  #7
Nov 9th, 2008
I didn´t understand that it was the projectname I should have written, sorry for that.
My projectname is simply "Form1" as in your testprogram "testform"
So now I guess I have written the *.cpp files correct. But still there is errors.

Form3.cpp
#include "stdafx.h"
#include "Form3.h"
#include "Form4.h"

Form4 ^Form3::SomeMethodA()
{
return gcnew Form4;
}

using namespace Form1;


Form4.cpp
#include "stdafx.h"
#include "Form3.h"
#include "Form4.h"

Form3 ^Form4::SomeMethodB()
{
return gcnew Form3;
}

using namespace Form1;


Exactly the same compileerror situation occurs anyway with this in place but I
will only have these compileerrors if I use these codes that would open eachothers
forms and the compiler only gives errors for Form4 and not Form3:
I dont know if there could be any more clues to the error.

'Form4' : no appropriate default constructor available
use of undefined type 'Form4'
left of '->ShowDialog' must point to class/struct/union/generic type


Form3.h
  1. Form4 ^form4 = gcnew Form4;
  2. form4->ShowDialog(); //open form4

Form4.h
  1. Form3 ^form3 = gcnew Form3;
  2. form3->ShowDialog(); //open form3
Last edited by Liszt; Nov 9th, 2008 at 11:11 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Include h files

 
0
  #8
Nov 9th, 2008
zip up the project minus object files and post it so that we can see what the problem is.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 122
Reputation: Liszt is an unknown quantity at this point 
Solved Threads: 6
Liszt Liszt is offline Offline
Junior Poster

Re: Include h files

 
0
  #9
Nov 9th, 2008
Thank You, I have zipped the project, the object files only took 18 kB unzipped so I left them there in case anyway.
I removed a file named: VC++ Intellisense DataBase wich took up 10.9 MB of memory.
It was not possible to upload the file with this in the folder.
I hope I am sending the project correctly.


Originally Posted by Ancient Dragon View Post
zip up the project minus object files and post it so that we can see what the problem is.
Attached Files
File Type: zip Form1.zip (820.0 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Include h files

 
0
  #10
Nov 10th, 2008
move the implementation of button1_Click() from Form3.h to Form3.cpp. Attached are new files. It still has link problems for unresolved external functions, but you just have to implenent them in the *.cpp files.
Last edited by Ancient Dragon; Mar 10th, 2009 at 1:13 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC