www.digitalmars.com         C & C++   DMDScript  

c++ - Newbie needs your help

reply E.T. <E.T._member pathlink.com> writes:
Very basic problem, I guess...

This file compiles with no problems:

// start of main.cpp

class A
{
int n;
public:
void check();
};

void A::check()
{
n=1;
}

void main()
{
A objA;
objA.check();
}

// end of main.cpp

But when I seperate it to 3 files: header, class functions implementation and
main, the compilation fails:

// start of header file

class A
{
int n;
public:
void check();
};

// end of header file

//start of class functions implementation file

#include "A.h"

void A::check()
{
n=1;
}

// end of class functions implementation file

//start of main file

#include "A.h"

void main()
{
A objA;
objA.check();
}

//end of main file

compilation output:

link MAIN2,,,user32+kernel32/noi;

OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

MAIN2.obj(MAIN2) 
Error 42: Symbol Undefined ?check A  QAEXXZ (void syscall A::check(void ))

--- errorlevel 1

------ Output completed (0.4 sec consumed) ------

What is my mistake?
Nov 19 2003
parent "Matthew Wilson" <matthew-hat -stlsoft-dot.-org> writes:
Are you dmc-ing both implementation files? e.g.

    dmc main.cpp funcs.cpp?

It looks like all you're doing is

    dmc main.cpp


"E.T." <E.T._member pathlink.com> wrote in message
news:bpfi2e$2ouk$1 digitaldaemon.com...
 Very basic problem, I guess...

 This file compiles with no problems:

 // start of main.cpp

 class A
 {
 int n;
 public:
 void check();
 };

 void A::check()
 {
 n=1;
 }

 void main()
 {
 A objA;
 objA.check();
 }

 // end of main.cpp

 But when I seperate it to 3 files: header, class functions implementation

 main, the compilation fails:

 // start of header file

 class A
 {
 int n;
 public:
 void check();
 };

 // end of header file

 //start of class functions implementation file

 #include "A.h"

 void A::check()
 {
 n=1;
 }

 // end of class functions implementation file

 //start of main file

 #include "A.h"

 void main()
 {
 A objA;
 objA.check();
 }

 //end of main file

 compilation output:

 link MAIN2,,,user32+kernel32/noi;

 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 MAIN2.obj(MAIN2)
 Error 42: Symbol Undefined ?check A  QAEXXZ (void syscall A::check(void ))

 --- errorlevel 1

 ------ Output completed (0.4 sec consumed) ------

 What is my mistake?

Nov 19 2003