|
...For those of you who are interested, this inquiry reaches a dramatic conclusion over at the Microsoft Technical Forums. I'm just SO HAPPY that I didn't make a TOTAL ASS out of myself, by attempting to offer some advice about something,...WELL, OK, BYE,...
cgraus[^]
And, More Analysis[^]
-- modified at 19:29 Tuesday 13th September, 2005
|
|
|
|
|
|
There is a AT protocal hardware, on which I want to build a http channel.
How to design?
Thanks!
|
|
|
|
|
#include <iostream>
using namespace std;
class A
{
int i;
public:
A(int ii):i(ii){}
int operator ++()
{
return ++i;
}
int operator ++(int)
{
int ntemp;
ntemp = i;
i++;
return ntemp;
}
int geti(){return i;}
};
int main()
{
A a(2);
cout << ++a << endl << a.geti() << endl;
}
The operator "<<" is evaluated from left to right how can a.geti() gets called first?
|
|
|
|
|
I don't understand the question (you could have placed some punctuation... )
well, if i am not on what you mean, please reformulate.
you're asking for why geti() is called before ++a ?
it isn't...
otherwise, i missed your point.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
you're asking for why geti() is called before ++a ?
it isn't...
I'm under VC++ 6.0 and saw with my own bear eye geti() is called before ++a.
You can make those member function involved announce themselves, then you'll see the calling sequence!
|
|
|
|
|
The order of evaluation is for the << operator only, not for the operands of the << operator. The left to right associativity of << means that your statement will look like
((((cout << ++a) << endl) << a.geti()) << endl);
That is, cout << ++a will be calculated first, then the result of that will be the LHS and endl will the RHS next time and so on. It doesn't mean that the compiler needs to evaluate ++a before a.geti(). The compiler usually will evaluate ++a and a.geti() (in any order it wishes to, IIRC) before starting to execute the << operator.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi there.
I am working on a project wich requires me to use matrices and do some computations on them. So I downloaded the LINPACK linear algebra library from
http://www.csit.fsu.edu/~burkardt/cpp_src/linpack/linpack.html
The library is very nice, offering a huge collection of very usefull matrix arithmetic.
I downloaded the source for the library which consisted of 2 .h files and 2 .c files. And when I try to compile the c files, using Visual Studio C++ 2003, I get two build errors:
linpack.c
c:\Documents Of I\UP\Year5 Semester2\EPR400\My Programming\TestMatrix\linpack.C(5668) : fatal error C1010: unexpected end of file while looking for precompiled header directive
blas1.c
c:\Documents Of I\UP\Year5 Semester2\EPR400\My Programming\TestMatrix\blas1.C(4532) : fatal error C1010: unexpected end of file while looking for precompiled header directive
So I need help to get the source code to compile on VS C++ 2003. I think I need to change settings for the precompiled headers section of the project properties but I dont have a clue what it all means.
Please help!
Thanks!
Ben
|
|
|
|
|
add to your c files #include "stdafx.h" if u are using then into a visual c++ project with precompiled header project option
NG
|
|
|
|
|
Or you could just edit your project properties to not include precompiled headers.
|
|
|
|
|
Hi.
Including the "stdafx.h" file in all the source files worked.
I couldn't turn of the Use Precompiled Headers option because the other source files in my project did indeed already include "stadafx.h".
Thanx for the help guys!!
|
|
|
|
|
I'm having trouble trying to do one on the implementation files of my project. can you plz help... i will attach the appropriate header file/s and .cpp files which I have completed, yet however that is one .cpp which is partially completed, can you really help with the definition of the member functions. The partially completed file is called EmployeeDatabase_template[1].cpp. i included the source code below for you to look at. plz help with definition of these member functions
#include "EmployeeDatabase.h"
#include
using namespace std;
EmployeeDatabase::EmployeeDatabase()
{ // Complete code.
people = 0; // The database is a vector of Persons.
size = 0; // The number of Persons in the database.
}
void EmployeeDatabase::getEids(vector &ids)
{ // Complete code.
}
string EmployeeDatabase::getName(int employeeID)
{// Complete code.
}
double EmployeeDatabase::getShoeSize(int employeeID)
{// Complete code.
}
void EmployeeDatabase::makePerson(string employeeName, int employeeID, double employeeShoeSize)
{//complete code.
}
int EmployeeDatabase::getSize()
{// Complete code.
return size;
}
here is the appropriate specification files(header files).
this is EmployeeDatabase.h
// A EmployeeDatabase consists of a vector of Persons;
// methods are supplied to retrieve all the employee IDs and
// to query the database for employee names and shoesizes using
// the corresponding employee id.
#include "Person.h"
#include
using namespace std;
#ifndef EmployeeDatabase_H
#define EmployeeDatabase_H
class EmployeeDatabase{
public:
EmployeeDatabase();
// Constructor:
// Makes an instance of an EmployeeDatabase containing no data.
void getEids(vector & ids);
// Returns a vector of all the employee ids in the vector people.
string getName(int employeeID);
// Returns the name of the Person with eid equal to employeeID.
double getShoeSize(int employeeID);
// Returns the shoesize of the Person with eid equal to employeeID.
void makePerson(string employeeName, int employeeID, double employeeShoeSize);
// Creates a new instance of Person using the input data
// and adds it to the vector people.
int getSize();
// Returns the number of Persons stored.
private:
vector people; // The database is a vector of Persons.
int size; // The number of Persons in the database.
};
#endif //EmployeeDatabase_H
This is Person.h
// A Person consists of the name, the employee ID and the shoe size.
// Methods are supplied to retrieve each of the three data items.
using namespace std;
#include
#ifndef Person_H
#define Person_H
class Person{
public:
Person(); // Default constructor.
Person(string personName, int personId, double personShoeSize);
// Constructor:
// Makes an instance of a person with the
// given data.
string getName();
// Returns the name of the Person.
int getEid();
// Returns the employer ID of the Person.
double getShoeSize();
// Returns the shoesize of the Person.
private:
string name; // The employee's name.
int eid; // The employee's ID.
double shoeSize; // The employee's shoesize.
};
#endif
PLZ WITH THE FIRST BIT OF CODE THE OTHER TWO ARE THE HEADER FILES. I JUST CANT FIGURE OUT HOW TO DEFINE SOME OF THEM.
|
|
|
|
|
hi,
i have one request if you want some help :
please edit.Modify your message and put the codes into <pre></pre> tags for us to see the indentations, and the blocs of code correctly. you could separate the files using several tag blocs.
one more thing :
use the < and > buttons at the bottom of the edit box to let us see the template parameters... (we do not see the vectors and so...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
ok. no worries, thanks for the swift reply.
I'm having trouble trying to do one on the implementation files of my project. can you plz help... i will attach the appropriate header file/s and .cpp files which I have completed, yet however that is one .cpp which is partially completed, can you really help with the definition of the member functions. The partially completed file is called EmployeeDatabase_template.cpp. i included the source code below for you to look at. plz help with definition of these member functions
<pre>
#include "EmployeeDatabase.h"
#include <vector>
using namespace std;
EmployeeDatabase::EmployeeDatabase()
{ // Complete code.
size = 0;
}
void EmployeeDatabase::getEids(vector <int>&ids)
{ // Complete code.
}
string EmployeeDatabase::getName(int employeeID)
{// Complete code.
}
double EmployeeDatabase::getShoeSize(int employeeID)
{// Complete code.
}
void EmployeeDatabase::makePerson(string employeeName, int employeeID, double employeeShoeSize)
{//complete code.
}
int EmployeeDatabase::getSize()
{// Complete code.
return size;
}
</pre>
here is the appropriate specification files(header files).
this is EmployeeDatabase.h
<pre>
// A EmployeeDatabase consists of a vector of Persons;
// methods are supplied to retrieve all the employee IDs and
// to query the database for employee names and shoesizes using
// the corresponding employee id.
#include "Person.h"
#include <vector>
using namespace std;
#ifndef EmployeeDatabase_H
#define EmployeeDatabase_H
class EmployeeDatabase{
public:
EmployeeDatabase();
// Constructor:
// Makes an instance of an EmployeeDatabase containing no data.
void getEids(vector <int>& ids);
// Returns a vector of all the employee ids in the vector people.
string getName(int employeeID);
// Returns the name of the Person with eid equal to employeeID.
double getShoeSize(int employeeID);
// Returns the shoesize of the Person with eid equal to employeeID.
void makePerson(string employeeName, int employeeID, double employeeShoeSize);
// Creates a new instance of Person using the input data
// and adds it to the vector people.
int getSize();
// Returns the number of Persons stored.
private:
// The database is vector of Persons.
vector <Person> people;
int size; // The number of Persons in the database.
};
#endif //EmployeeDatabase_H
</pre>
This is Person.h
<pre>
// A Person consists of the name, the employee ID and the shoe size.
// Methods are supplied to retrieve each of the three data items.
using namespace std;
#include<string>
#ifndef Person_H
#define Person_H
class Person{
public:
Person(); // Default constructor.
Person(string personName, int personId, double personShoeSize);
// Constructor:
// Makes an instance of a person with the
// given data.
string getName();
// Returns the name of the Person.
int getEid();
// Returns the employer ID of the Person.
double getShoeSize();
// Returns the shoesize of the Person.
private:
string name; // The employee's name.
int eid; // The employee's ID.
double shoeSize; // The employee's shoesize.
};
#endif
</pre>
PLZ CAN YOU HELP ME WITH THE FIRST BIT OF CODE THE OTHER TWO ARE THE HEADER FILES. I JUST CANT FIGURE OUT HOW TO DEFINE SOME OF THE MEMBER FUNCTIONS.
-- modified at 23:40 Monday 5th September, 2005
|
|
|
|
|
class A
{
int i;
public:
A(int ii):i(ii){}
int operator ++()
{
return ++i;
}
int operator ++(int)
{
int ntemp;
ntemp = i;
++i;
return ntemp;
}
int geti(){return i;}
};
int main()
{
A a(2);
cout << a++ << endl
<< a.geti() << endl;
getchar();
}
Why the result is "2, 2" instead of "2, 3". a++ seems doesn't operate on A::i?
|
|
|
|
|
and what does cout << ++a << endl << a.geti() << endl; return ???
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
and what does cout << ++a << endl << a.geti() << endl; return ???
This statement doesn't return anything, I think!
|
|
|
|
|
you think ? or you tested ?
in C++, postfixed ++ operator returns the value before the incrementation, while prefixed return the new value...
so, i ask you the question : what is the change when you switch the postfixed incrementation operation with the prefixed one ???
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
in C++, postfixed ++ operator returns the value before the incrementation, while prefixed return the new value...
I implemented the operation as postfixed ++ operator supposed to be: first return the operand before any modification and then imcrement it.
int operator ++(int)
{
int ntemp;
ntemp = i;
++i;
return ntemp;
}
But I wonder why the
int geti(){return i;}
seems reading another object?That is my question.
toxcct wrote:
what is the change when you switch the postfixed incrementation operation with the prefixed one ???
int operator ++(int)
{
int ntemp;
ntemp = i;
++i;
return ntemp;
}
Do you mean the operation in bold?If so, I just wanted next time when "i" get referenced, it got incremented!
|
|
|
|
|
no no no, i talk about the line i quoted in my first answer.
your post/pre-fixed ++ operators are well written for both goals, but i wonder what would happen if, instead of calling a++ , you were calling ++a .
you wrote :
cout << a++ << endl << a.geti() << endl;
equivalent to :
cout << a.operator++(1) << endl << a.geti() << endl;
Now, i suggest writing instead :
cout << ++a << endl << a.geti() << endl;
equivalent to :
cout << a.operator++() << endl << a.geti() << endl;
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
sorry toxcct I don't see you point!
toxcct wrote:
you wrote :
cout << a++ << endl << a.geti() << endl; equivalent to : cout << a.operator++() << endl << a.geti() << endl;
This is postfixed version, and a.operator++()shoud be in prefixed version.
toxcct wrote:
Now, i suggest writing instead :
cout << ++a << endl << a.geti() << endl; equivalent to : cout << a.operator++(1) << endl << a.geti() << endl;
This is prefixed version, and a.operator++(1) shoud be in postfixed version!
Finally I figured out why the result is incorrect:
in
cout << ++a << endl << a.geti() << endl;
The A::geti() gets called first that was before "i" get incremented
cout << ++a << endl ; cout << a.geti() << endl;
will produce the right result!But what exactly happened?
|
|
|
|
|
tss,
you finnally did what i told you from at the beginning...
what happened is that geti() got the value returned by postfixed ++ operator, that means, the old value, just because you were on the same instruction !!!
ps: sorry for the mix i made in my mind between operator++() and operator++(int). you are right
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
actually, prefix operator is not correct because it should return an l-value (e.g. int& instead of int). however, this implementation is not very logical, because increment operator should not return different type that the one where it is defined.
|
|
|
|
|
Zdeslav Vojkovic wrote:
actually, prefix operator is not correct because it should return an l-value (e.g. int& instead of int).
What do you mean by that?
Zdeslav Vojkovic wrote:
however, this implementation is not very logical, because increment operator should not return different type that the one where it is defined.
The implementation should look like:
A operator ++()<br> {<br> return A(++i); <br> }
?
|
|
|
|
|
Zdeslav Vojkovic wrote: actually, prefix operator is not correct because it should return an l-value (e.g. int& instead of int).
What do you mean by that?
Zdeslav Vojkovic wrote: however, this implementation is not very logical, because increment operator should not return different type that the one where it is defined.
The implementation should look like:
A operator ++()<br> {<br> return A(++i); <br> } ?
|
|
|
|