please i have a little problem creating a class and making it run. The class is created separately as a header file with it's source code.
whenever i build the source code of the class, i get an error that says: undefined reference to 'WinMain@16'. And whenever I run the main, it gives me the error: undefined reference to 'samclass::samclass'

here's my code

main

#include<iostream>
#include "samclass.h"
using namespace std;

int main(){
  samclass obj;

return 0;}

header

#ifndef SAMCLASS_H
#define SAMCLASS_H
#include <iostream>
using namespace std;

class samclass
{
    public:
        samclass();
        void printcrap();

};

#endif // SAMCLASS_H

header source code

#include "samclass.h"
#include <iostream>
using namespace std;
samclass::samclass()
{
}
void samclass::printcrap(){
cout<<"this is the real crap"<<endl;
}

I need help.

Recommended Answers

All 3 Replies

You don't compile each module down to *.exe, but instead just to object module then use the linker to link both object modules together at the same time. And you should be creating a console project, not a Windows project. The error you posted indicates you created the wrong kind of project.

You need to ensure that all 3 files will be included in your project. You have to set it up so that first samclass.cpp is compiled, creating samclass.o. Then main is compiled. When main compiles and sees samclass.h with undefined functions it will look for the object file and use it.

From your title it looks like you might be using Code::Blocks. If this is the case you should create a project and select Project->Add Files to ensure that all 3 files are accounted for.

ok thank you all for your help. I really appreciate

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.