Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Class Help

This topic is 6484 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

I''m getting this weird error about how my constructos can''t return values. I KNOW this, and I have no returns. But it gives me a odd error, and points to my { of the function. Can someone help? Here is the code. NOTE: This is just something I threw together to practice. It was designed to work in a text RPG.

#include "troll.h"

troll::troll(int power, apstring description)
	apstring	describe=description;

int troll::attack()
	return strength*6;

void troll::veiwStats()
	cout << "Strength:   " << strength << endl;
	cout << "Agility:    " << agility  << endl;
	cout << "Resistance: " << health   << endl;
	cout << "Brains:     " << brains   << endl;

int troll::defend()
	return health*6;

void troll::takeDamage(int damageRecived)

void troll::die()
		cout << "You have killed the vile beast! Congrats!\n";

void troll::look()
	cout << describe << endl;

Share this post

Link to post
Share on other sites
Does your class declaration have a semi colon at the end?

Also, what is apstring? is it a macro? is it a type def? if so, to what?

Why do you declare apstring describe = description, but then, not use it anywhere in your constructor?

You should always add a default constructor as well.

Share this post

Link to post
Share on other sites
AlekM: apstring is one of the 5 "AP Classes," designed to make your life with a couple of data structures easier.

The five are:


There are all templated (except for, of course, apstring) so you can create an array, matrix, stack. or queue of any data type you pass to the constructor.

Share this post

Link to post
Share on other sites
Here is the source for troll.h
The cplus2nb.h is just a small file with common files i use (inputs, outputs, etc).
#ifndef _TROLL_H

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

class troll
troll(int, apstring);

apstring description,describe;
int power;

int attack();
int defend();
void veiwStats();
void takeDamage(int);
void die();
void look();

int strength;
int brains;
int health;
int agility;
int currentHealth;


#define _TROLL_H

Share this post

Link to post
Share on other sites
I''ve never heard of the ap* classes, but C++ already has standard class templates: string, vector, list, map, deque, and a wide variety of algorithms:

#include <iostream>
#include <vector>
#include <string>
#include <list>

struct mydata { int unused[4]; };

int main(int argc, char* argv)
std::string s1 = "Hello";
std::string s2 = "World";
std::string s3 = s1 + " " + s2 + "!"; // make "Hello World!"

// output it
std::cout << s3 << std::endl;

std::vector<mydata> v1(256); // array of 256 mydata objects
std::vector<int> v2(10); // array of 10 ints

for( int x=0; x < v2.size(); x++ ) v2[x] = 0; // set each one to zero

v2.push_back(5); // add another int, handles resizing/copying

std::list<int> l1;

// add three ints

l1.sort(); // sort them to: 5, 7, 10

// automatic cleanup

These template classes are part of a template library called the STL. I would advise using this instead unless you have a real need to write your own low-level data structures. The STL is usually very highly optimized by the person who wrote the compiler, and as the interface is specified in the C++ language it makes your code a bit more portable and other C++ programmers will understand your code more easily.

Now, as to the original topic of discussion, I received that error recently, but I can''t remember what caused it... hmm... There seems to be nothing wrong with your code. Did you just copy and past portions of it? Perhaps the problem is one of the headers you included from troll.h (iostream.h - use iostream instead) or (cplus2eh.h - use STL).

Try commenting out the bodies of the functions using /* */ and remove the header inclusions from troll.h. Did this fix the problem?

Share this post

Link to post
Share on other sites
AlekM said it right. You need a semicolon at the end of the class declaration.

class troll


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!