Got to get out of that beginner habit i havny bothered in ages and more advanced tutorials are beginning to get indecipherable, i have a few questions, the first is should main always be called main? loads of my practice codes would wind up being called main, do i have to put them in their own folders and deal with it or can i call main anything? just worked out its fine so long as i include the header as i was typing, forget that, the other question is; is that the point of a project i can just go ahead and include different functions i have made before so soon enough all i have to do to make something is link stuff together? that sounds ace, should i start building up a project and lots of source and header files, is there a tut out there for this? if no its good advice for a fresh and bold beginner.
oh yeah and the function body in main, that could go in the source file, do i put the whole thing in there, wait how do i call it? i know why i got an error, its because i de=idnt use the scope resolution in main, is that it??
Kay, So the two errors i get are undefined referene to undefined reference to bunny::setname (std::string)the program spits out randomly created names.
and undefined reference to bunny::setname
heres the main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include<string>
#include<ctime>
#include<cstdlib>
#include "bunny namegenerator.h"
using namespace std;
main()
{
srand(time(0));
bunny bun1;
bun1.setname (namelist());
cout << bun1.getname()<<endl;
}
int getrand ()
{
return 1+(rand()%6);
}
string namelist ()
{
string namearray [18] = {"frufru ","baxter ","voldermort ","falafal ",
"fluffles "," flopsy "," panhandle ",
" bruchetta "," cottonflop "," serious ",
" bouviay "," lightening "," cellotape "," bonapart "," jackson "," gatsby "," junior "," the first "};
string none = namearray [getrand()%18];
string ntwo =namearray [getrand()*4%18];
string nthree=namearray [getrand()*7%18];
string fullname=none+ntwo+nthree;
return fullname;
}
|
here is bunny namegenerator.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include<string>
#include<ctime>
#include<cstdlib>
class bunny{
public:
void setname (std::string x);
std::string getname();
private:
std::string name;
};
std::string namelist ();
int getrand ();
|
and heres bunny namegenorator.cpp
1 2 3 4 5 6 7 8 9 10 11
|
#include "bunny namegenerator.h"
void bunny::setname (string x)
{
name = x;
}
string bunny::getname()
{
return name;
}
|