Class not seen by compiler???

Hey, I have an issue. VS 2013 isn't recognizing objects that I've declared when I use class functions.

I'm getting this error:
"Line 14 and 15: Error C2228: left of '.asciiToFpc6' must have class/struct/union"

Here's the relevant code:

Source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "fpc6.h"

using namespace std;

int main(){
	fpc6 t0();

	char c0 = 'a';
	char c1 = '0';
	cout << t0.asciiToFpc6(c0) << endl;
	cout << t0.asciiToFpc6(c1) << endl;

	return 0;
}


fpc6.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
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
75
76
77
78
79
#ifndef Fpc6
#define Fpc6

#include <string>
#include <fstream>
using namespace std;

	class fpc6{
private:
	//unsigned int fpc6Array[];
	int fpc6_size;
public:
	// default constructor, tracks number of fpc6 characters converted and the size of the packedfpc6 array
	//Graeme Hart
	fpc6() { 
		fpc6_size = 0; 
	}

// convert ascii char to unsigned int between 0 and 31
	unsigned int asciiToFpc6(char c)
	{
		unsigned int x = 0;
		if (c >= 97 && c <= 122){
			x = c - 97;
		} //a-z
		if (c == 13){ x = 26; } //CR
		if (c == 32){ x = 27; } //SPACE
		if (c == 39){ x = 28; } //'
		if (c == 46){ x = 29; } //.
		if (c == 59){ x = 30; } //;
		else{ x = 31; }
		return x;
	}

	// convert unsigned int between 0 and 31 to ascii char
	char fpc6ToAscii(unsigned int x)
	{
		char c = 'a';
		if (x >= 0 && x <= 25){
			c = x + 97;
		} //a-z
		if (x == 26){ c = 13; } //CR
		if (x == 27){ c = 32; } //SPACE
		if (x == 28){ c = 39; } //'
		if (x == 29){ c = 46; } //.
		if (x == 30){ c = 59; } //;
		else{ c = 63; }
		return c;
	}

	// accepts string with at least 6 ascii chars and returns a single unsigned
	// containing the first 6 characters packed into a single unsigned int.
	// If string length <6 then pad with spaces. 
	unsigned int pack6Fpc6IntoUnsigned(string s)
	{
		unsigned int x = 0;
		int bitShifter = 25;
		if (s.length() > 6)
			return -1;
		for (int i = 0; i < 6; i++){
			if(i >= s.length()){
				x | 27 << bitShifter;
			}
			else{
				x | asciiToFpc6(s.at(i));
				x << bitShifter;
				bitShifter -= 5;
				fpc6_size++;
			}
		}
		return x;
	}

//default destructor
	~fpc6() {
		fpc6_size = 0;
	}
};
#endif 


Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....
Last edited on
Just throwing this out there, but what if you made that class function, a regular function...
I only gave the relevant code because it makes it easier for you guys to parse whats going on, there are class-functions I haven't included on my post that need these ones to be there to work properly.
Last edited on
On line 15, make a a bool argument that does absolutely nothing, and initialize your class with a zero. Seems to work.
I'm a little confused about what you mean by that? Can I see the change you made?
Line 15 in the header: fpc6(bool b) { //the b is never used.

Line 10 in main: fpc6 t0(0); //Just the 0
Yeah... that DOES work. Do you think this is a VS bug? or is there some wonky thing in my code we both have so far missed?
On line 10 of Source.cpp, remove the brackets: fpc6 t0(); --> fpc6 t0;

Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....

The operators | & << >> do not modify the operands directly (what I mean is: for x << y; x and y will not be modified, but rather operator<< will return the result). I think what you want to be doing is using the bitwise assignment operators (it's midnight and I have no idea if that's what they're called or not): |= &= <<= >>=.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int main()
{
	int x, y;
	x = y = 10;
	std::cout<< "["<< x<< ", "<< y<< "]\n";
	x & 5;
	y &= 5;
	std::cout<< "["<< x<< ", "<< y<< "]\n";
	x = y = 10;
	x<< 5;
	y<<= 5;
	std::cout<< "["<< x<< ", "<< y<< "]\n";
}
[10, 10]
[10, 0]
[10, 320]

Notice how when the bitwise operators & and << are used, x remains the same, and when &= and <<= are used, y is changed.
I knew it was something simple and wonky. I don't recall Dev C++ being so picky about having empty parameters when declaring an object when I used to use it, but maybe it did too.

Also yes, bitwise assignment operators are what I wanted. Thanks!
Last edited on
From the tutorial (http://www.cplusplus.com/doc/tutorial/classes/ )
The default constructor is the constructor that takes no parameters, and it is special because it is called when an object is declared but is not initialized with any arguments. In the example above, the default constructor is called for rectb. Note how rectb is not even constructed with an empty set of parentheses - in fact, empty parentheses cannot be used to call the default constructor:

1
2
Rectangle rectb;   // ok, default constructor called
Rectangle rectc(); // oops, default constructor NOT called  



This is because the empty set of parentheses would make of rectc a function declaration instead of an object declaration: It would be a function that takes no arguments and returns a value of type Rectangle.
Topic archived. No new replies allowed.