error C2228: left of '.size' must have class/struct/union
Believe it or not, this line does not declare an instance of std::vector
named results
, calling the constructor taking a begin and end iterator:
std::vector<float> results(std::istream_iterator<int>(actualLineStream),
std::istream_iterator<int>());
This actually declares a function called results
that takes a parameter named actualLineStream
and another unnamed parameter, both of type std::istream_iterator<int>
.
Generally in C++, if something looks like a function, it will be parsed like one; the C++ standard requires it. This is really for backward compatibility with C - but this is so counterintuitive that it even has its own name: the "most vexing parse". Some compilers will even issue a warning if it encounters the most vexing parse.
It is related to the fact that these two lines are not equivalent in C++:
Foo bar; // Declares an instance of Foo named bar
Foo bar(); // Declares a function named bar that takes no parameters and returns a Foo
To fix it, you can add more parentheses around one of the arguments:
// +--------- Note extra parentheses!! ---------+
// | |
// V V
std::vector<float> results((std::istream_iterator<int>(actualLineStream)),
std::istream_iterator<int>());
Or simply declare each iterator separately:
std::istream_iterator<int> resultsBegin(actualLineStream);
std::istream_iterator<int> resultsEnd;
std::vector<float> results(resultsBegin, resultsEnd);
left of .size() must have class/struct/union
letter = roll(0, special.size());
special
and letters
are arrays. Arrays don't have methods. They don't have class members, they are just arrays.
You are probably looking for:
sizeof(specials)/sizeof(specials[0])
Ditto for letters
.
Error: C2228: left of '' must have class/struct/union
You made an error here:
DatabaseControl myDBControl();
You declared a function called myDBControl
taking no arguments and returning a DatabaseControl
.
Object declarations without any constructor arguments must omit the ()
:
DatabaseControl myDBControl;
This is related to (but is not precisely) the "most vexing parse", in that it's caused by the same language rule that statements are function declarations if they can be so parsed.
error C2228 left of '.setDay' must have a class/struct/union
setDay
is not static it needs to be called from an instance of the class, so you cannot call it like
DayOfYear::DayOfYear.setDay(d);
Instead, you'd call it off of this
this->setDay(d);
which is implicitly what is called within a class method, so you can just drop the this->
setDay(d);
In fact, you do this correctly for "January"
, then incorrect in the latter months.
error C2228: left of '.words' must have class/struct/union
You wrote
spectralFrameWord[0].words
but meant
spectralFrameWords[0].words
The compiler could not have made this much clearer. It said:
left of '.words' must have class/struct/union
So that tells you to inspect that which is to the left of words
to see why it does not fit the bill.
When you allocate with new sometype[...]
you must deallocate with delete[]
. Using std::vector<T>
might be more appropriate.
Error 22 error C2228: left of '.size' must have class/struct/union
v
is a pointer, so you need to use the pointer member access operator (->
) instead of the object member access operator (.
).
void Graph::explore(Vertex *v)
{
v->visited = true;
int total;
for(int i = 0; i < v->adj.size(); i++)
{
cout << v->name << " to "; // this should be v->name,
// not v->adj.name
if (!v->visited)
{
explore(v->adj[i]);
}
}
}
Left of . must have class/struct/union c++ error
.
has higher precedence than *
, so *fin.open(inputFilename, ios::in);
(and others) are interpreted as *(fin.open(inputFilename, ios::in));
, which is incorrect since fin
is a pointer.
Use brackets or better yet, ->
. Or even better, pass the parameters by reference, I don't see a need to pass by pointer.
Related Topics
Add Library Search Path to Clang
How to Call a C++ Method from C
Why Double Can Store Bigger Numbers Than Unsigned Long Long
Scheduling Task in Using C++ on Linux and Windows Machine
Compiler Support for Upcoming C++0X
Is There a Default Hash Function for an Unordered_Set of a Custom Class
C++ Error on Ms Visual Studio: "Windows Has Triggered a Breakpoint in Javaw.Exe"
How to Call a Constructor on an Already Allocated Memory
Optimizing a Branch for a Known More-Common Path
Plug-In Architecture Based C/C++ Application
How to Traverse a Boost::Multi_Array
Mbcs Error Building Mfc C++ Project with Visual Studio
Std::Locale Breakage on MACos 10.6 with Lang=En_Us.Utf-8
Gdb Nostop Sigsegv on a Specific Thread
Programmatically Getting Per-Process Disk Io Statistics on Windows