I have (2) errors, and I do not know how to fix them or even what to fix. I tried looking it up on the MSDN, but did not understand. I would appreciate any help I can get. Thanks!
You don’t have the constructor defined anywhere in your project, only declared. Probably because:
[ul][]you didn’t write the function body.[]you didn’t include the correct source file.[*]you didn’t include the correct libray.[/ul]
Canvas(int width, int height, char* windowTitle); //constructor
I also have the below code near the top of my .CPP file, declared after my function prototypes.
Canvas cvs(640,480, “try out”); //global object
My program includes one header file which declares my class “Canvas” and includes (2) other classes as well. My first function definition for class Canvas is also included in the header file. It is as follows:
void Canvas::initCT(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //set CT to the
//identity matrix
}
I also have a “rotate2D” and a “scale2D” included in that same header file. Is this allowed, or do my function definitions need to be in a .cpp file (separate from the class Canvas.h file).
Canvas(int width, int height, char* windowTitle); //constructor
Yes, this is the constructor declaration, but you need the definition too; the code for it.
I also have the below code near the top of my .CPP file, declared after my function prototypes.
Canvas cvs(640,480, “try out”); //global object
This is probably where you want to create an object of type Canvas, but the linker can’t find it’s constructor, which the compiler want’s to call.
My program includes one header file which declares my class “Canvas” and includes (2) other classes as well. My first function definition for class Canvas is also included in the header file. […] Is this allowed, or do my function definitions need to be in a .cpp file (separate from the class Canvas.h file).
You can define functions in a header, but you should only do that if you know the side effects. If you don’t know that, you should separate interface (header) and implementation (source).
Thanks Bob–You’re right, I didn’t include anything like what you said in my program. I’m not quite sure what you meant by your code, “m_n”. What is “m_n” Here is what I added though as my function definition:
Canvas::Canvas(int width, int height, char windowTitle)
{
char argv[1]; //dummy argument for glutinit
char dummyString[8];
argv[0] = dummyString; //hook up pointer
int argc = 1;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(20,20);
setWindow(0,(float)width, 0, (float) height); //default wrld wndw
setViewport0,width,0,height);
CP.set(0.0f,0.0f);
CD = 0.0f; //the current direction in degrees
Originally posted by kcay: Thanks Bob–You’re right, I didn’t include anything like what you said in my program. I’m not quite sure what you meant by your code, “m_n”. What is “m_n” Here is what I added though as my function definition:
Sorry, the “m_n” is just a notation that is used by some people that lets you know it is a member variable(the m part) and then n lets you know it is a number.