Hi,
Trying to do the simplest of simple c++ project importing from a file, and loading the contents into a vector.
For the life of me, I can't see where I've gone wrong.
The errors are:
||=== Build: Debug in classtest (compiler: GNU GCC Compiler) ===|
/usr/bin/ld: obj/Debug/main.o||in function `main':|
/home/linc/Documents/Workspace/classtest/main.cpp|23|undefined reference to `testStuff::testStuff()'|
/usr/bin/ld: /home/linc/Documents/Workspace/classtest/main.cpp|26|undefined reference to `testStuff::setsomeint(int)'|
/usr/bin/ld: /home/linc/Documents/Workspace/classtest/main.cpp|27|undefined reference to `testStuff::setsomestring(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
/usr/bin/ld: /home/linc/Documents/Workspace/classtest/main.cpp|23|undefined reference to `testStuff::~testStuff()'|
/usr/bin/ld: /home/linc/Documents/Workspace/classtest/main.cpp|23|undefined reference to `testStuff::~testStuff()'|
/usr/bin/ld: obj/Debug/main.o||in function `void __gnu_cxx::new_allocator<testStuff>::destroy<testStuff>(testStuff*)':|
/usr/include/c++/9/ext/new_allocator.h|153|undefined reference to `testStuff::~testStuff()'|
/usr/bin/ld: obj/Debug/main.o||in function `void std::_Destroy<testStuff>(testStuff*)':|
/usr/include/c++/9/bits/stl_construct.h|98|undefined reference to `testStuff::~testStuff()'|
||error: ld returned 1 exit status|
||=== Build failed: 8 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Can anyone point it out?
(I'm sure that when you do, it'll be "Oh! Yes, of course! How silly of me!")
classtest.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#ifndef CLASSTEST_H_INCLUDED
#define CLASSTEST_H_INCLUDED
#include <string>
using namespace::std;
class testStuff
{
public:
testStuff();
~testStuff();
void setsomeint(int);
void setsomestring(string);
int returnsomeint(void) const;
string returnsomestring(void) const;
private:
int someint;
string somestring;
};
#endif // CLASSTEST_H_INCLUDED
| |
classtest.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <vector>
#include "classtest.h"
#include <string>
using namespace std;
testStuff::testStuff()
{
// Nothing to see here
}
testStuff::~testStuff()
{
// nothing to see here
}
// Mutator function
void testStuff::setsomeint(int number)
{
someint = number;
}
// Mutator function
void testStuff::setsomestring(string nothery)
{
somestring = nothery;
}
// Accessor function
int testStuff::returnsomething() const
{
return someint;
}
// Accessor function
string testStuff::returnanother() const
{
return somestring;
}
| |
main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "classtest.h"
using namespace std;
int main()
{
vector<testStuff> classystuff;
fstream infile;
string intscratch;
string stringscratch;
infile.open("infile.txt", ios::in);
while(!infile.eof())
{
testStuff stuff;
getline(infile, intscratch, ' ');
getline(infile, stringscratch);
stuff.setsomeint(stoi(intscratch));
stuff.setsomestring(stringscratch);
classystuff.push_back(stuff);
}
return 0;
}
| |