|
Hi
Thank you very much for your time,
But am not still fully convinced anyway.
Regards
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
|
Private is a class scope (or meaning...) rule not an instance (or object) one.
Hence what happens inside Get method it is legal (an instance of the class can access private member of another instance of the same class). On the other hand
Zainu wrote: int main()
{
Shape s, s1;
s.x = s1.x;
}
it is INVALID because inside main you cannot access private member of (both s and s1 ) instances of the Shape class.
Hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Zainu wrote:
I am wondering why things are designed like this?
If things were not designed like this then how one can implement the copy constructor, assignment operator etc
One more pint if you remeber that if any member is used in a clss function the its gets prepent with this->. which is again the instance (object) of the class.
These are the reason why things are designed in that way. So that private member of a object can be used directly when there are used in a member fucnction.
Manoj
Never Gives up
|
|
|
|
|
Think of each class as a person.
Think of each method and variable as something that person owns.
You can assign many things different access modifiers: public, protected, private, ect.
If you make an item you own(variable or method) private or protected you don't want any other person(class) using it right? Now say you want to be nice and share, make it public and then other people(class) can use it.
Does that make it make more sense?
The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.
|
|
|
|
|
ExpertComing wrote: Does that make it make more sense?
Not even to those of us that are in the know.
ExpertComing wrote: The only way to speed up a Macintosh computer is at 9.8 m/sec/sec.
This would look a lot better as:
The only way to speed up a Macintosh computer is at 9.8 m/s2.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
KISS.
Internally a class must be able to access private members of an object of the same class so that it able to copy it or swap contents with it. That is you would find if very difficult (or impossible) to write copy constructors or “=” assignment operators if objects of the same class where not friends.
The ‘main’ example you supplied is different because the assignment is being made outside of the class objects and from the out side there is no friendship.
By the way, your ‘Get’ is an assignment (or copying) method and does not get anything.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I got something to work with my file output, and it all prints correctly except the 1st line
CString energyText;
which at the point I am looking at is "08MeV.dat" (confirmed!)
fstream newFile;
newFile.open (fileName, ios::out);
newFile<<'!'<
|
|
|
|
|
ldsdbomber wrote: newFile<<'!'<<energytext<<endl;< blockquote="">
Should be:
newFile << '!' << (LPCSTR) energyText << endl;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Putting this somewhere in the code would be a better solution:
template <typename CH, typename TR>
inline std::basic_ostream<CH, TR>& operator << (std::basic_ostream<CH, TR> &os, const CString &s)
{
os << static_cast<LPCTSTR>(s);
return os;
}
Steve
|
|
|
|
|
While it is obviously a different solution, what is it that makes it better?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: While it is obviously a different solution, what is it that makes it better?
1. Uniformity; you write a CString to the stream in the same manner as you do for other types.
2. Safety; you can't forget the cast and get into trouble.
3. Cleanness; you don't have ugly casts scattered throughout the code but rather centralised in one place.
4. Intuitive; it just works, without any special knowledge beyond that of normal C++ streams.
Steve
|
|
|
|
|
Stephen Hewitt wrote:
1. Uniformity; you write a CString to the stream in the same manner as you do for other types.
Thanks.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Put this somewhere in you code to enable this usage:
template <typename CH, typename TR>
inline std::basic_ostream<CH, TR>& operator << (std::basic_ostream<CH, TR> &os, const CString &s)
{
os << static_cast<LPCTSTR>(s);
return os;
}
Steve
|
|
|
|
|
what is the difference between the declaration and definition of pre and post increment operators(i++ and ++i).
Thank you
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: what is the difference between the declaration and definition
One defines, the other declares.
class A
{
void foo( void );
};
void A::foo( void )
{
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Please read the complete question .
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: Please read the complete question .
I did. My answer applies to any and all.
If, however, you are wanting to know the difference between the post-increment operator and the pre-increment operator, that's an entirely different question.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sorry for my bad framing of sentence.
I wanted to the implementaion and declaration difference between post and pre increment operators.
KIRAN PINJARLA
|
|
|
|
|
Since you haven't tried googling a little, here's a little help...
Increment and Decrement (C++)[^]
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi,
I have written a function in a DLL as follows
std::string Myclass::MyFunc()
{
std::string ret;
ret = "HHHHHHHHHHHHHHH"
return ret;
}
I am exporting this class and importing in client app.
What I am observing is that when I call this function from C++ client, if the number of charcters assigned to ret are less than 16 the program is working fine. But if the nuber of characters assigned to ret are 16 or greater, in client program it is giving exception while assigning the returned string to local string.
It is working in Debug mode but crashing in release mode.
Thanks in advance...
-- modified at 7:56 Friday 25th May, 2007
|
|
|
|
|
Make sure that for your executable and your dll you link to the same runtime library. And check that for both release and debug modes.
|
|
|
|
|
While debugging in release mode, the deallocate functiom from xmemory file is getting called for mor than 15 characters, while coming out of scope from function in client app.
My dll is not using MFC, but client app is using MFC lib.
Can you tell how to confirm executable and dll you link to the same runtime library?
Thanks in Advance.
|
|
|
|
|
sandeepkavade wrote: Can you tell how to confirm executable and dll you link to the same runtime library?
Depends of your IDE. For Visual Studio 2005, go in the project settings -> "C/C++" and check that the Runtime Library is the same for your dll and for your executable.
|
|
|
|
|
-- modified at 13:28 Friday 25th May, 2007
Never mind, I can't read
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|