Advertisement Jump to content
Sign in to follow this  

I break the project into smaller files and the program falls apart

This topic is 4986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My project have grewn a bit now and I decided to split it up in several files. Although its still just one class its good practice. The program works when its a single file but it doesnt when I break it up. Need help to see why. creature.h

const int TARGET_NUMBER = 20;
const int CELL_SIZE = 20;
const int CREATURES = 10;

class creature {
	creature();	//constructor
	void randomizeCells();
	void printCells();
	int calculateTotal();
	int calculateOffset();
	int abs(int i);	// makes sure a number if positive
	int cell[CELL_SIZE];


#include "creature.h"
#include <iostream>

creature::creature() {

void creature::randomizeCells() {
	// fill them with junk	
	for(int i = 0; i < CELL_SIZE; i++)
		cell = rand()%2;

void creature::printCells() {
	for(int i = 0; i < CELL_SIZE; i++)
		cout << cell;

int creature::calculateTotal() {
	// holder for the total number
	int total = 0;
	for(int i = 0; i < CELL_SIZE; i++)
		total += cell;
	return total;

int creature::calculateOffset() {
	int worth = this->calculateTotal() - TARGET_NUMBER;
	return abs(worth);

int creature::abs(int i) {
	if(i >= 0)
		return i;
	if(i < 0) {
		i *= -1;
		return i;

When I try to run it now it complains about cout is undecleared, but iostream is included just a couple of lines above. What did I do wrong when I split up the project into smaller files?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!