Illegal reference to non-static member

I'm trying to populate a vector (words) within my class. I'm getting the error:

"Illegal reference to non-static member" in the function calls "words_to_vector" and "is_regular_address".

This worked before I moved things into classes.

The examples I'm finding on line don't seem to address this particular scenario.

Here is my code. Hopefully nothing pertinent was edited out. The vector "words" is referenced in LOTS of other places in my code, and I'm not YET getting an error on it.

In "words_to_vector" I'm populating the vector. In "is_regular_address", I'm just referring to it.



AddressCls.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#include <vector>
#include <string>
#include <regex>

using namespace std;

class AddressCls
{
	 
public:
	AddressCls();
	AddressCls(string);

	~AddressCls();

private:
	vector<string> words;

	bool is_regular_address(vector<string>);
	bool words_to_vector(string, vector <string> &, string);
};


AddressCls.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "pch.h"
#include "AddressCls.h"
#include <regex>


using namespace std;

AddressCls::AddressCls(std::string instring)
{
	words.clear();
	words_to_vector(instring,words," ");
	word_beg = 0;
	word_end = words.size() - 1;
	address_struct address = {};
}
	

bool AddressCls::words_to_vector(std::string instring, 
std::vector <std::string> &words, std::string delim) {
	//parse on delimiter and store into vector
	std::string thisword;
	int start = 0;
	int pos = instring.find(delim, 0);
	while (-1 < pos) {
		thisword = pop_first_word(instring, delim);
		start = instring.find(delim, start);
		if (thisword != "") {
			words.push_back(thisword);
		}
		pos = instring.find(delim, 0);
		//get last one

	}
	if ((pos == -1) && (instring != "")) {
		words.push_back(instring);
	}

	return true;
}


bool AddressCls::is_regular_address(vector<string>words) {
	if (words.size() > 0) {
		if (AddressCls::isnumeric(words[0].substr(0, 1)) || (AddressCls::isnumeric(words[0]))) {
			return true;
		}
		else return false;
	}
	else { return false; }
}

AddressCls::~AddressCls()
{
}
Last edited on
did you change the name of is_street_address and forget to update that change somewhere?
it does not exist here.

this error message is usually tied to trying to call a class method without an object.
instead of
variable.function(stuff);
you forget and just do
function(stuff);//error, nonstatic method call
Sorry, that should have read "is_regular_address". Typo on my part.

So, within the class, when I'm calling methods within it, do I use AddressCls::process_address(), or is there a better way. And is there a difference between calling private methods and public, when within the class.

I know outside of the class it would be:

AddressCls addr;

addr.process_address();
Last edited on
> Hopefully nothing pertinent was edited out
sadly, the error message was.
¿what non-static member? ¿which line number?

post the error message verbatim
AddressCls::process_address()

should be one of 2 things

not in the class:
variable.process_address()
or if inside the class
this->process_address() //long version
where
process_address() is understood to be 'this->' one //short version

within the class everything is public.
outside the class, if the method is private variable.function() will fail (error, attempt to call private method).
Last edited on
Thanks jonnin. that "this->" reference is what I needed.

To ne555, I did post the error message verbatim. It was in the post subject line. The line numbers aren't generated until after I post the code, so I will have to learn to go back in and edit my post to address the generated line numbers. The offending lines were 18 and 42. I see I also posted the error message verbatim within the body of the post. I'll try to highlight it next time.
Last edited on
Topic archived. No new replies allowed.