473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2572
"Lee Garrington" <ze******@zen.co.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
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
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...
18
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?...
20
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
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...
4
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. ...
5
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
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
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...
22
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.