I've been getting a very strange error when I use codeblocks, the "undefined reference error. Now if I was using a library which I hade to link to I would understand why I would get this but I'm just making an incredibly simple test class.
The code:
Test.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
class test
{
int a;
char b;
public:
void set_int(int i);
void set_char(char c);
void show();
};
#endif // TEST_H_INCLUDED
Test.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include"Test.h"
#include<iostream>
void test::set_int(int i)
{
a = i;
}
void test::set_char(char c)
{
b = c;
}
void test::show()
{
std::cout << a << "\t" << b;
}
Basically, it removes any invalid data (such as files & cache entries) that once pertained to the project; thus, purging the project of all out-of-data information.
I know that creating a new project won't change anything since I've tried this in three other projects with different classes and the same errors keep coming up.
It will however recognize that the class is there because if I change the main function to this:
1 2 3 4 5 6 7 8 9 10 11
int main()
{
std::cout << "Hello world!" << std::endl;
test t;
/*t.set_int(4);
t.set_char('b');
t.show();
*/
return 0;
}
On the workspace pane, on the left-hand side, locate your project. Right-click it an select the Add files... menu item. Code::Blocks will automatically organise your files based on the extension.