|
Cool! I just remember how simple concepts such as that where very confusing. We may take them for granted, but any one who ask such a question needs clarification.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
1. The prior replies were correct, the two forms are the same.
I like it to the left because then it says what it is, a pointer to some type, char* (pointer to a char, or a string of chars), or a pointer to an int: int*; also, when you do a typecast ( "(char*)" )it looks like this:
char* pointer =(char*) malloc(...); -- since the malloc() function returns a pointer to a chunk of memory. See the part about deferencing below, for yet another reason to shift * to the left.
2. However, as far as having several variables declared in one line, you can do it, but, in general, style guides typically suggest that in modern code, there should only be one (not more than one) declaration per line of code:
char c = '\0';
char* p, i, x; is confusing -- the * only applies to p, not i or x.
// as an extra here in this example, I'm initializing the variable 'c' to equal the 'null terminator,' ('\0'), that is used by the C language to terminate (i.e., end, all strings); also called a sentinel. The C run-time libraries look for this character to detect that the string has ended.
3. Next, you can declare a pointer (pChar) to point to the character (c):
char* pChar = &c;
Here, I'm initializing the pointer to have a value set equal to the address of the variable 'c'. The "&" operator returns the address of what follows it. The pointer variable 'pChar' has the special job of holding the address
of another variable's address, that is, where it 'lives' (resides) in memory. This can be used as one way to prevent crashes, due to uninitialed vars.
4. Now you can do this
char next = *pChar;
And next will have the value also held by 'c' the null ('\0'), which I could have set to any char, such as 'a', 'b', etc. When the asterisk is applied to the initialized pointer, in this way *p, then it is being "dereferenced" meaning that you are going to get the value of the variable the p hold the address of -- yes, it's called indirection, and can be confusing. But this give C the power to do many amazing things, when done right.
5. The struct definition in C let's you declare a variable (as simple struct object, or as a pointer to one of those struct objects, that you are defining the struct to represent, when you define the struct (the 'p' in this case, if I recall correctly) -- this is somewhat strange in that most other languages don't allow for this.
Your text book should show many examples of the linked list. That stuff gets very complex, very quickly, so get someone to show/explain it (fast!) and save yourself hours/days/weeks of pain and strain -- it is much harder than you think, at first. Good Luck!! Tons of examples exist in the net: Checkout: http://www.cppworld.com/tutorials/?tutorial=structures
|
|
|
|
|
so with in main there is no need to declare a object of struct if we want as p could access the data.
I mean there is no need to do -:
int main()
{
Point p1, p2;
because we can do something like this now i.e.
p.data, p.link;
Is that right.
Thanks a lot to all of you to make it so clear.
|
|
|
|
|
Excellent! That will give the original poster much information to dwell on.
‘Mike_V’ was correct as I stated and your knowledge appears to be just as good. I am a teacher by nature, not by vocation, and therefore I like to clarify things when I can.
Why you where writing your post I was doing the same, so take a look and tell me what you think.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Interesting handle you gave yourself ‘Software_Specialist’, add in training to that.
You have gotten off the point of your original post; which had to do with pointers and not types.
In you little code snippet you declare the variables ‘p1’ and ‘p2’, the variable ‘p’ does not exist unless it was declared globally. The values stored in ‘p1’ can be accessed via ‘p1.data’ and ‘p1.link’, and the values stored in ‘p2’ can be accessed via ‘p2.data’ and ‘p2.link’.
You can create your own data type at any time and any where in your code, whether it is a ‘struct’ or a ‘class’.
int main()
{
struct MY_DATA_TYPE { int a, b, c; } my_data;
my_data.a = 1;
my_data.b = 2;
my_data.c = 3;
…..
}
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
The books you have read are correct, they are the same thing. I personally like writing it as char* p , but that is deceptive, as the symbol ‘*’ applies to (modifies) the variable ‘p’ and not the main type (char). The current trend is to declare each variable on an individual line to avoid confusion by those who do not understand that little detail. Once you understand what the ‘*’ symbol means in your code, then you can decide how best to express that meaning by its placement in your own code.
When declaring a variable with the modifier ‘*’, you are stating that the variable will be holding the address (location in memory) of the location where the value, or values, is actually stored. This is referred to as an indirect reference, meaning that it tells you where the value is stored and does not represent the value itself. When using a pointer variable you can use either ‘*p’ or ‘p->’ both of which is called a reference. A reference refers to the actual value(s) stored in memory and can be used to modify that value(s).
The simplest way I know how to explain it is this:
If I know the address of your house and can send you a letter at any time, then I know where you live (that is a pointer). If I go to your house as a guessed, then I can observer and affect the contents of your house, if I so choose (that is a reference).
That is enough, I only took one class on programming and that was because I was having trouble understanding the concept of pointers. Once I understood that the rest of it became non-relevant to me.
Good Luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Thanks a lot to all of you.
Now its making much sence and i could now continue with programming of Linked List based problem.
|
|
|
|
|
hello,
I want to get edit box value from an application.I am using GetWindowText Api,but returning caption not the value written in edit box.Using spy++ , window class name is QWidget , window caption is something which is not visible.
Any idea?
|
|
|
|
|
Only one; look up QWidget which is a cross platform library for creating applications.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I am trying to modify an existing project in Visual C++ 6.0. (I do not do a lot of C++ programming, but am helping a friend.)
When I try and build a project, I receive some errors. There are 11 errors, but I have only copied two of them to shorten the post.
SUMMARYT.OBJ : error LNK2001: unresolved external symbol "protected: virtual void __thiscall CSummaryTableView::OnDraw(class CDC *)" (?OnDraw@CSummaryTableView@@MAEXPAVCDC@@@Z)
SUMMARYT.OBJ : error LNK2001: unresolved external symbol "public: __thiscall CTableViewEdit::CTableViewEdit(void)" (??0CTableViewEdit@@QAE@XZ)
This is an existing program that is already compiled, I just added a new field to the report. I have confirmed that the Constructors have been built. What else could be causing these errors?
Visual C++ is new to me, so I would appreciate some help. Thanks.
JAG
|
|
|
|
|
I recommend ‘Rebuild All’, these problems usually occurs because a partial build relies on previous information that is no longer valid. If that does not work, then there is a missing code file (it could be corrupted) or an intermediate file is giving you grief. Check a few FAQs to be sure, but you may need to delete to ‘*.ncb’ file in order to force the compiler to recreate the entire code from scratch.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Dear all,
Now I have six data in includes:
3 data Xw, Yw, Zw in FlexGid at i row and j column
and 3 data m_iA, m_iB, m_iC in edit box form Interger individually. So please help me export these data to text file .txt in which these data is arrange correctly following form:
P1={X Xw,Y Yw,Z Zw,A m_iA,B m_iB,C m_iC}
P2={X Xw,Y Yw,Z Zw,A m_iA,B m_iB,C m_iC}....Pn
I just start with VC++, so please show me more detail. Thank you very much.
|
|
|
|
|
You mention ‘FlexGrid” and if that is where your data is stored, then I would look at the documentation for that to find you answer. Most things with the title ‘Grid’ or ‘Spreadsheet’ in them have a means to export their contents as a ‘TAB’ delimited file. That is a file where the individual fields are separated by the ‘TAB’ character, with each line representing as single entry (or record) per line.
Hopefully some who has use it will show up shortly.
Good Luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I used VS 2005 with MFC
My SDI software has been created in English but i want to change it in french language.
I try to changed all ressource but my software is always in english (untitled when i do a new document) and any message in english.
How can i try to changed my default language?
thanks
|
|
|
|
|
|
For many years, I have been "naughty" in reusing my classes by copying the relevent files in to my current project in MSVC - I knew that I should be generating a library, but I was lazy !!! I have now generated a library and tried to alter my project settings to use MyLibrary. (I have experimented with a known working project) I have referenced the library by stating the path in MSVC/Project/Settings/Link and adding it to "Object/Library modules".
When I compile/link the project without making any source code changes (apart from adding a constructor for a class contained in MyLibrary), I get loads of errors (just under 200 !!), one of which I quote below:-
nafxcwd.lib(wincore.obj) : error LNK2005: "public: virtual void __thiscall CWnd::OnFinalRelease(void)" (?OnFinalRelease@CWnd@@UAEXXZ) already defined in mfc42d.lib(MFC42D.DLL)
If I remove the constructor for the class contained in MyLibrary, it links without error.
Can someone pin-point what I am doing wrong in the setup of my project within the MSVC (vers 6.0) build and usage of MyLibrary ?
Doug
Doug
|
|
|
|
|
(I should have examined the errors more carefully !!!) I've found the problem - when building the library, I should have selected "Use MFC in a shared DLL", so that double linkage does not occur when linking the project using the library. Hope this is understandable (and helps someone else in the future searching for the solution to this "problem" !!)
Doug
|
|
|
|
|
Sorry in advance for long post..
Ok well let me fill you in on the bigger picture::
I am at the early stages of learning visual C++ and have a few decisions to make before I can start, and would like to hear what people think(especially if you work in the industry)..Im I on the right track or are there obvious flaws in my planning?... Here is my situation:
I have:
Hnd Computer science(same as first 2 years of Uni.)
written basic programs in C experience in OO: Java and Smalltalk programming degree level projects..not vey big..email client..shopping checkout/stock system etc etc
I want to learn and start earning money as a visual c++ programmer,
I have the oppertunity of a 6 month work placement at my local University, I can use the time to learn visual c++ with a view to getting a job as a programmer + get some experience. But I have to complete some kind of programming project at the end of the 6 months, possibly an app that the University may actually use, the idea being that the app with full documentaion etc..can be used to try and get a job somewhere...
Im using the free Express edition of visual studio(for now), hopefully at some point in the near future I can purchase the full version...can you see any drawbacks to using the express version over the full version..in terms of what im trying to achieve?...also with Express, will there be a licencing issue if the University decide to use the completed project/stand-alone app(compiled in Express)
Now my rough unsure plan is get a hold of a book like
'Ivor Horton's Beginning Visual C++ 2005'
[url]http://www.amazon.com/Ivor-Hortons-Beginning-Visual-Programmer/dp/0764571974/ref=pd_bbs_sr_1/002-3234138-6754445?ie=UTF8&s=books&qid=1173625687&sr=1-1[/url]
...and work through the exercises and experiment a bit(1 month)..then at the end of the book I should be more familiar with the subject and ready to start the project, I also have access to the uni library and the web for more general c++ issues that will arise that are not covered in ivors book..as it looks like quite a broad intro to vs c++
To give you an idea of the scale of the project(which can be anything that can be completed within 4 months)..my initial project ideas are:
Messenger type program that would run on the uni network..features: search/buy/sell used books, printer credit, suggestion box, weather, Calender/planner
Basic Firewall application
Im thinking of these types of apps because because I imagine they require the exploration of the different areas of visual c++ in reference to networks, files guis, internet, security, database etc...and hopefully give me a good grounding introduction..Also feel free to suggest alternative projects that you think more suitable?
How realistic is this plan?
|
|
|
|
|
The only recommendation I can give you for you project is the KISS principle (Keep It Simple Stupid), which applies to all programming. As to the compiler you are using, that is the universities problem and not yours. If they decide your code is good enough to use, then it is up to them to let you or someone else compile and test it on a version that is licensed for commercial usage. As to the language you choose to use, the ones offered by Microsoft are much easier to use for internet communications than most, because they are designed with that in mind. The C++ language is great, especially because it hides some of the details that C does not. Keep in mind your ultimate goal; meaning that if you know, and have experience with the latest languages (C#, etc…) you increase your odds of finding a job.
My preferred language is C++, I recommend searching for ‘Thinking in C++” online as the author provides copies of his works for free. That should give you a good start and please buy a copy when you have the funds, he admits he was a bad C programmer (and I agree), but more than understands programming now (opinion submitted 10 years ago) . Once you understand his works then purchase a copy of ‘The C++ Programming Language’ by ‘Bjarne Stroustrup’ the creator of C++. There are other book that delve into the language a little deeper and ‘Bjarne Sroustrup’s’ web site mentions a few of them.
When you can answer this question for you self, then you will know the power of C++:
What is the most important (or defining) function in the STL?
HINT: Without it the ‘strong guarantee’ would not be possible.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
somebody would tell me why there would be a exception when the Format funciton excuted?
The codes like this:
COleDateTime time(1982,10,17,12,30,0);<br />
CString strTime=time.Format("%H%M");
the assert message like:
File:afxwin1.inl
Line:22
I'm eager for someone's hand! Thanks
|
|
|
|
|
Generally, the way to tell is to check line 22 of afxwin1.inl.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I use Visual C++ 6.0
the 22nd line of file "afxwin1.inl" only is a MACRO !
I don't know how to do it.
Thanks
|
|
|
|
|
When an assert fails, the error message shows you the check that was being done. What does the message say?
|
|
|
|
|
the assertion dialog like below:
Debug Assertion failed!<br />
<br />
Program:...<br />
File:afxwin1.inl<br />
Line: 22<br />
<br />
For information on how your program can cause an assertion failure,See the vasual C++ documentation on asserts.<br />
<br />
(Press Retry to debug the application)
Thanks
|
|
|
|
|
now,I know,the statement can work well only on Release mode, if you run it on Debug mode ,the assertion will be throwed allways!
Somebody would tell me,Why?
Thanks
|
|
|
|
|