473,804 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner C++ problem....

Hey,

Recently I decided to learn C++ so that I could port over one of my Java
programs to make it faster. Basically everything has ported over fine so
far until I came up against the following problem....

The problem involves 2 classes. A Game class and a Solver class. The Game
class updates the game board etc. and the Solver class is called upon when
it needs to solve the board. To do this I have an instance of Solver
declared in Game so that Game can start it when needed and I also have an
instance of Game in Solver so that the solver can call methods in Game to
update the board throughout the solve. I simply cant get it to work though.
I have #ifndef'ed both the .h files but they just cant #include each other
without erroring. This is done no problem in java.

Surely there is a way to do what I want in C++. If there is can someone
please tell me how?

Much appreciated.
Lee
Jul 19 '05 #1
2 2590
"Lee Garrington" <ze******@zen.c o.uk> wrote...
Recently I decided to learn C++ so that I could port over one of my Java
programs to make it faster. Basically everything has ported over fine so
far until I came up against the following problem....

The problem involves 2 classes. A Game class and a Solver class. The Game class updates the game board etc. and the Solver class is called upon when
it needs to solve the board. To do this I have an instance of Solver
declared in Game so that Game can start it when needed and I also have an
instance of Game in Solver so that the solver can call methods in Game to
update the board throughout the solve. I simply cant get it to work though. I have #ifndef'ed both the .h files but they just cant #include each other
without erroring. This is done no problem in java.

Surely there is a way to do what I want in C++. If there is can someone
please tell me how?


Look up "forward declaration" in the FAQ or on Google.

Victor

Jul 19 '05 #2
Lee Garrington wrote:
Hey,

Recently I decided to learn C++ so that I could port over one of my
Java
programs to make it faster. Basically everything has ported over fine
so far until I came up against the following problem....

The problem involves 2 classes. A Game class and a Solver class. The
Game class updates the game board etc. and the Solver class is called
upon when
it needs to solve the board. To do this I have an instance of Solver
declared in Game so that Game can start it when needed and I also have
an instance of Game in Solver so that the solver can call methods in
Game to update the board throughout the solve.
That is an endless loop. Your Game contains a Solver, which contains a
Game, which contains a Solver, which....
You'd need an infinite amount of memory for it. One of your classes must
contain a pointer or reference to the other instead of an instance.
I simply cant get it to work
though. I have #ifndef'ed both the .h files but they just cant
#include each other without erroring.
Of course not. If you #include the solver somewhere, that would start by
#including the Game header, which in turn starts by #including the
solver header.... again an endless loop.
This is done no problem in java.
Java is very different from C++.
Surely there is a way to do what I want in C++. If there is can
someone please tell me how?


Ever had a look into the FAQ to this group? You can find it at:

http://www.parashift.com/c++-faq-lite/

You might be interested in question 38.11.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2992
by: jvax | last post by:
Hi all, I hope I'm posting in the right NG... I have a data text file I want to read from a c++ program. the data file goes like this: 90 # number of balls 33 42 13
5
3083
by: Richard B. Kreckel | last post by:
Hi! I was recently asked what book to recommend for a beginner in C++. I am convinced that you needn't study C in depth before learning C++ (though it helps), but cannot find any beginner's book which isn't aimed at people coming from C/Pascal/Java/Delpi/whatever... However, there seem to be plenty such books for all those other languages. Is there really no literature for people trying to learn programming by starting with C++? ...
18
2929
by: mitchellpal | last post by:
Hi guys, am learning c as a beginner language and am finding it rough especially with pointers and data files. What do you think, am i being too pessimistic or thats how it happens for a beginner? Are there better languages than c for a beginner? For instance visual basic or i should just keep the confidence of improving?
20
2299
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
10
2431
by: See_Red_Run | last post by:
Hi, I am trying to figure out how to get started with PHP/MySQL. Everything I've read so far says to start with PHP first. I was expecting something like Visual Basic Express or some other type of free IDE. So I discovered that I needed to download a virtual server, so I downloaded OmniSecure and followed the set up instructions as far as I could figure them out. So here is where I'm stuck. 1) While trying to set up and configure...
4
2818
by: Bails | last post by:
Hi Im an absolute beginner in programming and am using VB.Net Express. To start my larning I decided to do a "Real World" app instead of "hello world" and am creating a Poker Countdown clock. I pretty much have most things under control and have set it up as follows: Form 1 Contains a DataGridView where users enter in information includeing the length of each round, small blind & big blind (its for
5
2754
by: macca | last post by:
Hi, I'm looking for a good book on PHP design patterns for a OOP beginner - Reccommendations please? Thanks Paul
10
4473
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
1
1464
by: H. Fraser | last post by:
I've downloaded all of the code and video dealing with the RSS Reader but when i try to run it, it throws an exception, saying 404 page not found. And, As a total beginner, i've no idea where the problem is in the code or else I would have sorted it out my self. If anyone have a fix for it please tell me. Thank you in advance. Hugh Fraser
22
18154
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.