I just started creating header files of my project but i quiet am not getting it right i use code blocks 16.0 currently i am stuck with " undefined reference "
here is the code
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include "abc.h"
usingnamespace std;
int main()
{ abc p;
system("cls");
cout<<"\n\n\t OPENING HEADER FILE FUNCTION NOW ";
p.something();
return 0;
}
abc.h
1 2 3 4 5 6 7 8
#ifndef ABC_H
#define ABC_H
class abc
{ int a;
public:
void something();
};
#endif // ABC_H
abc.cpp
1 2 3 4 5 6 7
#include "abc.h"
#include<iostream>
usingnamespace std;
void abc::something()
{ a=5;
cout<<"\n\t\t ...... IT WORKS ...... "<<a;
}
error message
C:\TURBOC3\BIN\ASAP\MAIN.o :MAIN.cpp|| undefined reference to `abc::something()'|
You might want to try creating a new standard console project with a different name (foo). If this first compiles, do these steps :
+ Create the header foo.h (if it doesn't exist)
+ Copy all content of abc.h to foo.h
+ In main.cpp, include foo.h and copy 'n' paste this line from abc.cpp :
1 2 3 4
void abc::something()
{ a=5;
std::cout<<"\n\t\t ...... IT WORKS ...... "<<a;
}
... before the function main()
+ Apply your previous main() function
+ Replace every ("abc") you can find in your foo solution project with ("foo")
+ Compile the solution and let us know your program result.
That doesn't necessarily mean that they are part of your project. Open the menu 'View' and activate 'Manager'. You will find a tab 'Projects' where all the files are listed which belongs to your project. Add the missing file...