Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 44 45 [46] 47 48 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95976 times)

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #675 on: December 21, 2010, 01:25:57 pm »

I'm working in C++, and some of my cpp files are getting unwieldy.
Is there an way to split up a cpp into multiple parts?
My soul class is getting so long that I have finding functions in it even with a search function. (due to so many search results)

I figured using #include and multiple files would work, but there were issues with scope or something.

Any insight would be appreciated.
#include would be your best bet. Try breaking your classes up into smaller ones, it's all about organization.
You can cut the file up into bits, and then, in a Makefile, `cat a.cpp b.cpp c.cpp > tmp && g++ tmp && rm tmp`, but that's ugly.
« Last Edit: December 21, 2010, 01:28:37 pm by ILikePie »
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #676 on: December 21, 2010, 01:39:29 pm »

What?

I don't know what that means.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #677 on: December 21, 2010, 01:40:52 pm »

Anyway, on to importing. How do I import custom classes? I've got this so far, but it doesn't work.
Well, for what it's worth, I've just imported my first custom class in NetBeans. This involved, building the class, for it to have a jar, then adding the jar to the libraries of my project (although it might be only relevant to the NetBeans interface, and I've got no idea how you'd do it otherwise), and finally importing the class with the package name.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #678 on: December 21, 2010, 01:41:53 pm »

I'm working in C++, and some of my cpp files are getting unwieldy.
Is there an way to split up a cpp into multiple parts?
My soul class is getting so long that I have finding functions in it even with a search function. (due to so many search results)

I figured using #include and multiple files would work, but there were issues with scope or something.

Any insight would be appreciated.

What I've seen people do is forward declare all the functions that'll be needed in other .cpps and make that into a header to attach to the files, keeping all the juicy stuff in the actual .cpps.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #679 on: December 21, 2010, 01:55:31 pm »

Anyway, on to importing. How do I import custom classes? I've got this so far, but it doesn't work.
Well, for what it's worth, I've just imported my first custom class in NetBeans. This involved, building the class, for it to have a jar, then adding the jar to the libraries of my project (although it might be only relevant to the NetBeans interface, and I've got no idea how you'd do it otherwise), and finally importing the class with the package name.
That's a bit of a roundabout way. If you've got the source code of the class, you can just make an additional class in the preferred package, copy the source code into said class and include said class (and package, via the using command, though if you're using netbeans it'll offer to solve that for you). Essentially the same method that you'd use when making your own classes, but this time you're stealing someone else's work :P
Doing it this way also makes it easier to extend or change the functionality of any custom classes, because you don't have to go back and build a new jar every time you change something.
« Last Edit: December 21, 2010, 01:58:14 pm by Virex »
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #680 on: December 21, 2010, 02:06:17 pm »

Anyway, on to importing. How do I import custom classes? I've got this so far, but it doesn't work.
Well, for what it's worth, I've just imported my first custom class in NetBeans. This involved, building the class, for it to have a jar, then adding the jar to the libraries of my project (although it might be only relevant to the NetBeans interface, and I've got no idea how you'd do it otherwise), and finally importing the class with the package name.
That's a bit of a roundabout way. If you've got the source code of the class, you can just make an additional class in the preferred package, copy the source code into said class and include said class (and package, via the using command, though if you're using netbeans it'll offer to solve that for you). Essentially the same method that you'd use when making your own classes, but this time you're stealing someone else's work :P
Doing it this way also makes it easier to extend or change the functionality of any custom classes, because you don't have to go back and build a new jar every time you change something.
Well, I don't know... I think it just feels cool that I can do this (roundabout way). And, well, you don't copy java.* classes into your code... err if you can.
Also, as I pretty much need to use the same class in the same implementation in two different applications... I don't think it would work your way.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #681 on: December 21, 2010, 02:12:31 pm »

Eww, Beans. Try using Emacs, it's great fun, and way cooler than all those shiny IDEs. Can your editor do this?
That's a bit of a roundabout way. If you've got the source code of the class, you can just make an additional class in the preferred package, copy the source code into said class and include said class (and package, via the using command, though if you're using netbeans it'll offer to solve that for you). Essentially the same method that you'd use when making your own classes, but this time you're stealing someone else's work :P
Doing it this way also makes it easier to extend or change the functionality of any custom classes, because you don't have to go back and build a new jar every time you change something.
Uh? I don't understand. Should I copy the source code into my .java file and use a using command? Currently I have them compiled at the same time, which... compiles. It gives me an error at run time though.
Code: [Select]
import libDib.*;
import java.io.File;

class Generator {
    public static void main(String[]args) {
    File file = new File("./image.dib");
    Canvas canvas =  new Canvas(64, 64, Draw.white);
    Bitmap DIB = new Bitmap (canvas);
    DIB.write(file);
          System.out.println("Ahem!");
    }
}

--------

ron@Tux ~/code/java $ java -jar Generator.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Canvas
    at Generator.main(Generator.java:7)
Caused by: java.lang.ClassNotFoundException: Canvas
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 1 more

« Last Edit: December 21, 2010, 02:15:52 pm by ILikePie »
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #682 on: December 21, 2010, 02:20:08 pm »

I think you'll need someone who knows Emacs better...
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #683 on: December 21, 2010, 02:33:13 pm »

Eww, Beans. Try using Emacs, it's great fun, and way cooler than all those shiny IDEs. Can your editor do this?
Can't watch that right now... but, I guess, I've got a thing for shiny IDEs. Probably because I was introduced to programming through a shiny IDE Delphi. Plus I just love how NetBeans handles component placing, like multiple grids to snap to - margin at the edge of the frame, several margins between components, edge alignment - just relaxing to look at. Although, I guess it could be counted as a form of procrastination.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #684 on: December 21, 2010, 02:48:57 pm »

You mean the GUI builder, right?
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #685 on: December 21, 2010, 03:06:17 pm »

Oh, yeah. I think a while back Ron specifically said that he liked Emacs for the transparency of the GUI manipulation, or maybe it was someone else.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #686 on: December 21, 2010, 03:15:04 pm »

I figured using #include and multiple files would work, but there were issues with scope or something.

Any insight would be appreciated.
Nope, not as far as I know. I've got a Engine.cpp, Engine_init.cpp, Engine_event.cpp, Engine_loop.cpp and only one Engine.h for all of them. Just don't press F11 in Code::Blocks and it'll be fine.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #687 on: December 21, 2010, 10:37:07 pm »

Eww, Beans. Try using Emacs, it's great fun, and way cooler than all those shiny IDEs. Can your editor do this?
That's a bit of a roundabout way. If you've got the source code of the class, you can just make an additional class in the preferred package, copy the source code into said class and include said class (and package, via the using command, though if you're using netbeans it'll offer to solve that for you). Essentially the same method that you'd use when making your own classes, but this time you're stealing someone else's work :P
Doing it this way also makes it easier to extend or change the functionality of any custom classes, because you don't have to go back and build a new jar every time you change something.
Uh? I don't understand. Should I copy the source code into my .java file and use a using command? Currently I have them compiled at the same time, which... compiles. It gives me an error at run time though.
Code: [Select]
import libDib.*;
import java.io.File;

class Generator {
    public static void main(String[]args) {
    File file = new File("./image.dib");
    Canvas canvas =  new Canvas(64, 64, Draw.white);
    Bitmap DIB = new Bitmap (canvas);
    DIB.write(file);
          System.out.println("Ahem!");
    }
}

--------

ron@Tux ~/code/java $ java -jar Generator.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Canvas
    at Generator.main(Generator.java:7)
Caused by: java.lang.ClassNotFoundException: Canvas
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 1 more


You need to import canvas into this class.

With java packages, they keep everything they need to run internal.

Otherwise just importing JFrames would bring in the canvas class, and a shitton of classes with subclasses. Which may not be what the developer wants.
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #688 on: December 22, 2010, 12:37:00 am »

I figured using #include and multiple files would work, but there were issues with scope or something.

Any insight would be appreciated.
Nope, not as far as I know. I've got a Engine.cpp, Engine_init.cpp, Engine_event.cpp, Engine_loop.cpp and only one Engine.h for all of them. Just don't press F11 in Code::Blocks and it'll be fine.

How do you have it set up?

Please tell me your secret, that would really help my productivity.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #689 on: December 22, 2010, 01:22:43 am »

What exactly are you having a problem with? If it's just getting multiple source files to work in general, it depends on your compiler and IDE (if you use one), if it is something worse, like splitting some large unsplitable thing like a massive class, though...
Logged
Eh?
Eh!
Pages: 1 ... 44 45 [46] 47 48 ... 78