I have a question about c++ programs in general. I have Borland
c++ v3 for DOS at home. It comes with an editor and has a mnu-based
compile command. It however, gives me warnings like : "Functions
containing while are not expanded inline" every time I have a while loop
in a class's public function. What does it mean and how can I fix it ?
Also, what does it error : "Member function must be called or
its address taken" mean ? It occurs when I try to call a function withing
another one in the same class...here is an example.
int search (char c) {
curr=head;
while (curr->next!=NULL) {
if (strcmp(c,curr->ch)==0) return 1;
curr=curr->next;
}
return 0;
}
and...
void process (char c) {
if (search(c)==1) increment; // this line has the error
else add(c); // where it says search(c)
}
that's it for now...thanks...
Amith :)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Amith Ganesan : gan...@ecf.utoronto.ca
When you do the following:
class foo {
...
myFunc() {
while(count<10) {
...
}
do stuff...
}
...
};
Then function myFunc() is an "inline" function. This means that everytime
you call the function (for example, x.myFunc()) instead of jumping to a
common function body, the code for the function is inserted into the
location where it is called. This is why C++ doesn't slow to a crawl with
all it's tiny 2-line functions. This way, doing something like:
class foo2 {
int x;
int get_x() const { return x; }
};
Doesn't actually slow down your program. Whereever you use get_x() member
function, the function call is replaced with a direct reference to the
member x.
The warning "functions containing while not expanded inline" means exactly
that; Even though you "requested" that the function be expanded inline,
the compiler will not do so because of the while loop. To get rid of the
warnings, either define the function out-of-line (using foo::) or turn off
that warning.
> Also, what does it error : "Member function must be called or
> its address taken" mean ? It occurs when I try to call a function withing
> another one in the same class...here is an example.
You must include () after a function name if you want to call it. I
believe your "increment" is a function name.
- Paul
> I have a question about c++ programs in general. I have Borland
> c++ v3 for DOS at home. It comes with an editor and has a mnu-based
> compile command. It however, gives me warnings like : "Functions
> containing while are not expanded inline" every time I have a while loop
> in a class's public function. What does it mean and how can I fix
> it ?
It's just a warning. Member functions that are defined inside the
class declaration are considered inline functions (as well as any
functions with the "inline" prefix to their definition). In C++, an
inline function is not supposed to be inline'd regardless. It's only
meant to be a indicator to the compiler to inline the function IF it
can or thinks it should.
All the warning is saying is that the compiler is not going to inline
your search() member function.
> Also, what does it error : "Member function must be called or
> its address taken" mean ? It occurs when I try to call a function withing
> another one in the same class...here is an example.
>
> int search (char c) {
> curr=head;
> while (curr->next!=NULL) {
> if (strcmp(c,curr->ch)==0) return 1;
> curr=curr->next;
> }
> return 0;
> }
>
> and...
>
> void process (char c) {
> if (search(c)==1) increment; // this line has the error
> else add(c); // where it says search(c)
> }
>
> that's it for now...thanks...
From the code above, I can't see what your compiler is talking about.
Are you sure that the "if(..." line above is exactly as it appears in
your code?
Carl.
> compile command. It however, gives me warnings like : "Functions
> containing while are not expanded inline" every time I have a while loop
Last time I have this error is when I miss a brace bracket somewhere
before the error code. It does not necessary be the line right in front
of the line. It could be one or two block of codes before
> Also, what does it error : "Member function must be called or
> its address taken" mean ? It occurs when I try to call a function withing
> another one in the same class...here is an example.
>
I think you call the function using:
eg. increment
instead of increment()