Jump to content

Can anyone here help with C++ ?

Sign in to follow this  

Recommended Posts

Come on, we've got to have a few programmers on this forum surely? :P

 

Anyway, basically I'm a little confused on just what I'm supposed to place in header files. I've not done a lot with C++ (no classes, only done a little on them in Java), although I gather that class definitions can go in Header files.

 

I was initially creating a series of functions in a menus.h file.

 

Stuff like:

 

displayMainMenu()
{
// Code
}

displaySubMenu01()
{
// Code
}
displaySubMenu02()
{
// Code
}

 

However an issue arose when I tried to call a header function from inside the header file, eg:

 

displayMainMenu()
{
   displaySubMenu01();
}

displaySubMenu01()
{
// Code
}

 

I get an error along the lines of "'displaySubMenu01()' was not declared in this scope", where 'displaySubMenu01()' is one of my menu functions, and this error comes up several times for each menu function I call in the first menu function.

 

After doing some googling, it 'appears' that I should only use a header file for declarations, ie:

 

void displayMainMenu();

void displaySubMenu01();

void displaySubMenu02();

 

I've also read that I should then use a separate .cpp file as a library file, say menus.cpp, and put the function content in that file. If this is the case, how do I get my main.cpp file to interact with this other menus.cpp file.

 

Despite some searching all I've been able to read is contradictory information and confusing forum posts. Hopefully someone moderately good with C++ can help. :(

 

EDIT:

 

Small update, just created a menus.cpp file (containing the functions themselves) and a menus.h file (containing the function declarations, assuming that's even the right word for this, I've seen the word 'prototype' used to describe this as well). I've moved stuff around, and included menus.h in both menus.cpp and main.cpp.

 

The program appears to function, but is this the correct way of doing things?

Feel free to PM me about almost anything and I'll do my best to answer. :)

 

"Beware of what you ask for, for it may come to pass..."

Share this post


Link to post

This might be a bit late (probably?) but this might help you:

http://www.cs.bu.edu/teaching/cpp/writing-makefiles/

 

The first parts explain what is done if you have a project with several source/header files.

 

As you said, only declarations should be in header files. The implementation should be in

seperated source files which then will be compiled into object files (.o) which in turn are

linked together into the executable (or a library, whatever you want).

 

If you use an IDE (like microsoft visual c++) it is easier then explained above (since you

don't have to do the compiling and linking manually) but you will need to look up the IDE

manual/tutorials for what to do to create and manage projects with many different files.

 

 

Hope that was all right, it is quite some years ago I last done something with C/CPP. :?

Share this post


Link to post

The IDE I use is Netbeans. Somewhat annoyingly, despite C++ being an object-orientated programming language, we've not been taught about classes and objects in C++. :(

 

EDIT: Here's the link I used to read up on code organisation: http://www.gamedev.net/page/resources/_/reference/programming/languages/c-and-c/organizing-code-files-in-c-and-c-r1798

Feel free to PM me about almost anything and I'll do my best to answer. :)

 

"Beware of what you ask for, for it may come to pass..."

Share this post


Link to post

Sorry, I use Python, and while I'd give you advice, there is a chance I'd get it wrong.

Hi Friend.

Share this post


Link to post

Well, I'm sure you will learn about classes and objects soon enough in your class.

It is easier to learn C++ if you have learned the basics that are C.

Or at least it was for me. :)

 

Well, netbeans, lets see...

I think you actually only need to add new source and header files to your project

and include the headers whereever you like and the rest like compiling and linking

them in the right order and dependancies should be done by netbeans.

 

So in other words, what you have done before (described in the edit part of your

first posting) should be fine and working so long as you use netbeans to manage

your project of course.

 

Also the posted link of yours pretty much explains it all too just in different words

then the one I posted. :)

 

You could also try google for something like 'netbeans cpp tutorial', maybe you will

find some nice tutorial about it all?

Having examples explained and able to test them at once yourself helped me alot too.

Share this post


Link to post

I should probably mention now that I got source and header files to function fine, however any advice on learning C++ etc is great.

 

I don't have any more lectures for a while as it's the Summer holidays, but I'm hoping to teach myself some more stuff over the Summer. Any advice is of course greatly appreciated.

 

A friend of mine recently wrote a python script that could read data off of a web page. I looked in to trying to do this in C++ but didn't get very far, and have now ended up reading some text about programming networking, client-server communication, etc. It's all interesting but rather complicated and beyond anything I've done before (or so it appears). Got any advice for proceeding here? For further knowledge, I code on Windows and value good coding practice where I can, and would ideally like to make stuff that could run on multiple platforms without modification, but after looking in to this whole networking business, it would appear that there are platform specific libraries for each operating system and they do things differently, making that multi-platform aim impossible, at least at my coding level (and without purpose as I've not got any aims to release anything, I'm just trying to learn stuff).

 

To summarise: creating a program in C++ that can read data off a web page would be cool.

 

I'd also like to clarify that I am not after copy-paste solutions and using code I don't understand. I'm much more interested in learning stuff. :D

 

 

I have also renamed the topic as the subject has now changed.

Feel free to PM me about almost anything and I'll do my best to answer. :)

 

"Beware of what you ask for, for it may come to pass..."

Share this post


Link to post

I can't give you explicit code or examples, it is too long ago for me, so yeah

only some general hints. :?

 

If networking in C++ is too complicated for you, then you still need to learn more.

I had the same problem. When I first came across 'sockets' I didn't even under-

stood half of it. :D

Well, half a year later or so after much programming, testing and building simple

stuff for myself, it was far easier to understand.

 

So, if you want to learn more try searching for c++ tutorials, simple as that.

Most explain from a simple 'Hello World!' over file/stream operations up to of course

networking and for example directx programming. In short, all you need, one step at

a time. There are countless of them so I can't give you a specific ones. Just a quick

search and you will find many useful websites with them. :)

 

The best is to use several at once even if you might do the same thing again.

Sometimes it is better to learn the stuff from many different angles/perspectives

then only from one source.

Also most good tutorials have example programs explained and coded for each

chapter, so you then can try them out for yourself, learning by doing in short.

 

Also useful is a bookmark (or a book) too to some C/C++ reference. They are

always useful if you forgotten something or want more detailed information about

a specific part you are currently working on.

 

Well... also try to start with simple tasks and tools first. They don't have to be

useful at first, simply to learn the mechanics. Play around, try to break the

programs sometimes even, helps learning how to handle bugs that don't want to

be found.

My first selfmade 'program' was a small text based rpg game with a simple battle

simulation. It was utterly stupid and badly made, but was fun to do nonetheless

and hooked me up on C/C++ for quite some time. :)

So start small and keep up climbing until you reach the programs you want to make.

 

On another note, keep up the idea of cross plattform programing!

There are not enough people who would still do that but it is dead useful for

everyone else. On that matter netbeans probably should work out for you, I think

there are several versions of it for each of the platforms?

Share this post


Link to post

I'm pretty new to programing myself, I work with C# so I have a limited knowledge of C++ though there are a few similarities as far as I can tell.

 

If developing programs for multiple platforms is what your after you want a CLI or (Common Language Infrastructure). If you want to learn more about what that is, here is a wiki page: http://en.wikipedia.org/wiki/Common_Language_Infrastructure . Basically your looking at developing for .NET or Mono, .NET will allow you to run your program on any windows platform that that has a working and up to date version of .NET Framework installed. Mono supports Macs and Linux from what I've read.

 

As far as learning to read data from websites, you want XML, here is a wiki page: http://en.wikipedia.org/wiki/XML

If you want to see some XML right now. Go to the top of your browser and click on the "View" Menu and select "source" or "page source", depends on what browser your using. a window should open up containing the XML code fore this web page. While this looks overwhelming, this is actually simple human readable code. If you'd like a nice quick video explaining XML, try this: http://msdn.microsoft.com/en-us/beginner/bb308812.aspx

 

I know that it's for a C# lesson but this video focuses primarily on XML and will help you understand the basics of the Syntax. If you want to write a program that can read web data your going to need to understand the basics of XML before you can write code that can read and translate XML in your program.

 

I wish I could provide more help but I'm still learning myself.

Share this post


Link to post

http://thisgamesux.net/vb/

 

It may be a "hack" site, but it does have a section for programming, and hackers are the epitome of professional programmers. They can link you to resources seldom used, but very useful. They can also help you debug code if you want.

 

This is another site to try out... http://www.gamedeception.net/content/

 

(another "hack" site, but some of the best programming/debugging stuff available on the net is there)

Don't insult me. I have trained professionals to do that.

Share this post


Link to post

I need to learn some basic script so I can make quests in Oblivion I have no idea were to start though :(

Share this post


Link to post

Start with wodpress, move to html, then make your way to Java :lol:

 

No but seriously, I recommend to start with python, it was an educational/clearer then c++ experience for me while it lasted and a lot of small arcade games are made on it. The point is, it is easier to use/learn (IMO) and it's capabilities are arguably much higher then most of the other alternative languages.

 

But if you want to learn C++ first learn C#

"When a son is born, the father will go up to the newborn baby, sword in hand; throwing it down, he says, "I shall not leave you with any property: You have only what you can provide with this weapon."

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in the community.

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


×
×
  • Create New...

This website uses cookies, as do most websites since the 90s. By using this site, you consent to cookies. We have to say this or we get in trouble. Learn more.