|
Class Help
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.
thanks
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.
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.
AlekM: apstring is one of the 5 "AP Classes," designed to make your life with a couple of data structures easier.
The five are:
apstring
apvector
apmatrix
apstack
apqueue
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.
The five are:
apstring
apvector
apmatrix
apstack
apqueue
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.
"Be that word our sign in parting, bird or fiend!" I shrieked, upstarting —"Get thee back into the tempest and the Night''s Plutonian shore!-just 2 of 96 lines from E.A.P.'s "the Raven"
Here is the source for troll.h
The cplus2nb.h is just a small file with common files i use (inputs, outputs, etc).
The cplus2nb.h is just a small file with common files i use (inputs, outputs, etc).
|
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:
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?
#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.insert(5);
l1.insert(10);
l1.insert(7);
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement