obj\Release\main.o:main.cpp:(.text.startup+0x23f)||undefined reference to `List_strm::List_strm()'

I'm getting the above error while experimenting with the stuff below.
I followed some teachign material examples that use the classes in the exact same way but when I try to make my own simple project it doesn't work.

The point was to build a beginners input stream on my own then have it push that value into a vector.

I created object User(n).
Object User(n) will be returned in my function list_strm::get().
In main I want to set object User Main=(the return value of ls.get())
List_strm ls, was created to accept that input as mentioned above.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include "std_lib_facilities.h"

using namespace std;

void createV(vector<int> &);


class User{
public:
char kind;
string Naym;
 int age;

 User(char k): kind(k) {};
 User(string n): Naym(n) {};
 User(int a): age(a){};
 User(string n, int a):Naym(n),age(a){};
};

class List_strm
{
public:
    User get();
    void putback(User u);
    List_strm();

};

List_strm ls;

User List_strm::get()
{
    if(full){
        full=false;
        return buffer;
    }

    char ch;
    cin>>ch;

        if(isalpha(ch)){
        string n;
        n+=ch;
        {
            while(cin.get(ch)&&(isalpha(ch))) n+=ch;

        return User(n);
        }}

    return 1;

}



/*void Print(const vector<User>& Users)
{
    for(int i=0;i<Users.size();++i)
    {cout << Users[i] <<endl;}

}*/


int main()
{

User in=ls.get();

vector<User> Users;
Users.push_back(User(in));


}


I know I have unused object, but I will use them later. Right now I want to learn to get this basic thing down.
Last edited on
Remove line 26, which declares a function that is neither defined nor needed.
... How so?
You get an error because the linker can't find the definition of the List_strm() constructor.
That is similar to the error as in this code below?

The thing that's bothering me is that both of these examples, the one included below and the one I posted to start this thread, come from a book and I think I am doing them exactly the same... In the book it shows the code is supposed to run fine...
javascript:post1064708.edit()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


struct Date{
 int y;
 int m;
 int d;
 Date(int y , int m  , int d );
};
int main()

{
    Date today={1978,6,25};


    cout<<today.m<<"\n"<< today.d<< "\n"<<today.y;

}


Here is where I took the Lst:strm example from: http://stroustrup.com/Programming/Solutions/Ch7/e7-1.cpp

The example below is what I based my List_strm class code on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Token_stream {
public: 
    Token_stream();   // make a Token_stream that reads from cin
   //..........
};


Token_stream ts;        // provides get() and putback() 

 int thisexampleis valid():
{
    Token t = ts.get();
//.....
}

Last edited on
Later in the same example (from http://stroustrup.com/Programming/Solutions/Ch7/e7-1.cpp ), the function is defined:

1
2
3
4
5
// The constructor just sets full to indicate that the buffer is empty:
Token_stream::Token_stream()
:full(false), buffer(0)    // no Token in buffer
{
}

Last edited on
Topic archived. No new replies allowed.