|
For starters, am I wrong in thinking your variables, being declared in the constructor, will be deleted in the constructor also ? They need to be globals.
Linked lists are not so hard, the best thing is to sit down with a piece of paper and draw out the structure so when you're knee deep in the code you have a mental picture of what is meant to be going on. I did a quick sort of a linked list once, now THAT was confusing....
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Okay, I made those variable static...
I've made a bunch of changes. I think my header file is coming along. I still do not know where to begin with this linked list thing.
/* mp3list.h
Your classes must all be declared in a header named mp3list.h.
Their definitions must reside in the file mp3list.cpp
(capitalize those correctly). */
/*
Mp3 Class
Stores information about an mp3 file: artist name, song title, and
bit rate (an integer greater than 0 that represents kbits / sec).
The constructor accepts all values as parameters
(strings arguments should be passed by reference).
Two public methods must be defined in the class:
1. equals( const Mp3 & ): returns true if the passed argument's
instance variables are equal to the current instance and false
otherwise.
2. display(): displays the Mp3 data in the following form
(using example data):
Artist: Nirvana
Title: Smells Like Teen Spirit
Bit Rate: 128 kbits/sec
This method doesn't return a value.
*/
//prevent multiple inclusion of header
#ifndef __mp3list_h__
#define __mp3list_h__
#include <string>
class Mp3
{
public:
//constructor
Mp3(string &Artist, string &Title, int &Bit){
static string art = Artist;
static string tit = Title;
static int bit = Bit;
}
bool equals(const Mp3& ComparedMp3) const {
return if ((art == ComparedMp3.art) && (tit == ComparedMp3.tit) && (bit == ComparedMp3.bit));
}
void display(){
cout << "Artist: " << art << endl;
cout << "Title: " << tit << endl;
cout << "Bit Rate: " << bit << endl;
}
}
/* Mp3ListNode Class
An object to represent a single node of the linked list.
*/
typedef Mp3ListNode *Mp3ListNode_ptr;
class Mp3ListNode
{
public:
/* constructor
Two instance variables are needed: a pointer to an Mp3 object
(the data held by the node) and a pointer to an Mp3ListNode that
points to the next node in the chain. The constructor must take
the three Mp3 data values (artist, title, rate) as arguments and is
responsible for creating an instance of Mp3 using the given data and
to save it in its instance pointer variable. It should also
initialize the pointer to the next list node to NULL
*/
Mp3(string &Artist, string &Title, int &Bit){
static string art = Artist;
static string tit = Title;
static int bit = Bit;
static Mp3ListNode_ptr curr;
static Mp3ListNode_ptr next = null;
}
/*
Three public methods must be defined in the class:
1. getMp3(): returns a copy of the pointer to the Mp3 object.
2. getNext(): returns a copy of the next Mp3ListNode pointer.
3. setNext(Mp3ListNode *): sets the values of the next Mp3ListNode
pointer to the passed pointer argument.
*/
getMp3() const {
return curr;
}
getNext() const {
return next;
}
//do I need a return type here? what return type is a pointer?
setNext(Mp3ListNode* SentNextMp3ListNode) {
next = SentMp3ListNode;
}
}
----------------------------------
/* mp3list.cpp
Mp3List
An object that represents a linked list. It provides methods for
common list operations such as adding, deleting, searching, and
inserting.
/*
The object should have three instance variables:
An Mp3ListNode pointer that points to the head (first) node of the
list, another Mp3ListNode pointer that points to the tail (last)
node of the list, and a count of the number of nodes currently in
the list. The constructor for the class takes no arguments and
initializes both pointers to NULL and the counter to 0 (the list
is created empty).
*/
typedef Mp3ListNode *Mp3ListNode_ptr;
class mp3list
{
public:
mp3list() {
Mp3ListNode head = null;
Mp3ListNode tail = null;
Mp3ListNode count = 0;
}
/*
Several public methods must be defined by the class:
1. getNumNodes(): returns the current number of nodes in
the list.
*/
int getNumNodes()
{
return count;
}
/*
2. add(const string &, const string &, int): Adds an
entry to the end of the list. Arguments passed
correspond to artist name, song title, and bitrate.
*/
void add(const string& addart, const string& addtit, int addbit)
{
Mp3ListNode_ptr new_node = new Mp3ListNode;
strcpy(new_node->mp3.art, addart);
strcpy(new_node->mp3.tit, addtit);
new_node->mp3.bit = addbit;
if (count == 0)
{
new_node->tail = ;
new_node->head =
/* i am completely lost here
3. find(const string &, const string &, int): returns a pointer
to the Mp3 that matches the given arguments (artist, title, and bitrate). If no matching element is found, it returns NULL.
4. del(): deletes all the nodes in the list. No value is returned.
5. del(const string &, const string &, int): deletes the entry
that matches the given arguments (artist, title, bitrate) and
returns true. If no match is found then no deletion takes place
and the method returns false.
6. insert(const string &, const string &, int, int): inserts at the
given index position and returns true if successful. If the index
is out of bounds, then no insertion takes place and the method
returns false.
7. display(): traverses all the nodes and calls each Mp3's display()
method to produce output in the format:
List data - total node count: 6
---------- INDEX 0 -----------
Artist: Nirvana
Title: Smells Like Teen Spirit
Bit Rate: 128 kbits / sec
---------- INDEX 1 -----------
Artist: Fila Brazilia
Title: Tunstall & Californian Haddock
Bit Rate: 128 kbits / sec
*/
|
|
|
|
|
Hi,
I am developing an MFC SDI application on Microsoft Visual C++ 6.0. The development is being done on Windows 95 whereas the deployment will be on Windows 2000.
I would like to know whether anyone out there has done something of this kind - development on Windows 95 and deployment on Windows 2000. I am anticipating some problems as regards API calls.
I would appreciate it if anyone who has had a similar experience get back to us with details!
Thanks,
Arvind
|
|
|
|
|
Hi,
I have never had any problems from Win95 -> Win2k, only the other way around...
There was some issues with Win95 -> NT, but it seems pretty much solved with Win2k...
- Anders
|
|
|
|
|
That really depends. Obviously you can't make Win2k specific API calls and still test your app on your Win95 machine. If you're going to stick with API calls that are the same (or close enough) between the two, you shouldn't have many problems.
|
|
|
|
|
I disagree with the previous posts - You definitely need to test on 2K if the app's going to be used on 2K!
The major problematic area when going from 9x to NT/2K is in security. There isn't any security on 9x, so your programmers may be sloppy and not pay attention to security parameters to API calls. The code works fine on 9x, but chokes with access denied errors on NT/2K.
For example, when the code opens a registry key, it might request KEY_ALL_ACCESS access. That's fine on 9x, but will not work on NT/2K unless the user has admin rights. In general, requesting ALL_ACCESS to anything is Bad because it will break for non-admin users.
--Mike--
http://home.inreach.com/mdunn/
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
-- Buffy
|
|
|
|
|
Agreed,
Other problems are things such as resource usage which is limited on Win9x (to 2MB), but effectively unlimited on Win2K.
Different threading behaviour due to no Win16 Mutex, a lot of low level stuff is different as well, although that may not bother you. Depends what you are writing.
Also developing on Win2000 would be more robust - no system crashes due to a bad pointer etc.
Definitely test on 2000.
Stephen Kellett
|
|
|
|
|
Would someone have a simple example of a smart pointer..I want to allocate memory for structures & classes...
I have seen the examples here, but they are over my head, I'm new to VC++.
If there's one example without worrying about synchronization & Threads, I would be happy.
Thanks,
Gerry.
|
|
|
|
|
#include <memory>
std::auto_ptr<cmyobject> p = new CMyObject;
When p goes out of scope, it's automatically destroyed.
|
|
|
|
|
Will this work for C-style Structures.
I want to create an array of structures on the heap & deallocate when the function goes out of scope.
Or do I need to put the structure inside a class?
I have about 5 variables that need allocated on the heap, 4 are BSTRs & one is an array of structures.
Gerry.
|
|
|
|
|
auto_ptr doesn't work for arrays because it only calls delete rather than delete []. If you need arrays, why not use std::vector instead? For the BSTR's use bstr_t
|
|
|
|
|
I'm working on my own tooltip class and I need to find the width and height of the mouse cursor.
I've tried GetSystemMetrics with SM_CXCURSOR/SM_CYCURSOR but that only returns what looks to me to be the maximum dimentions of the mouse cursor, not the current mouse cursor width and height.
Any suggestions?
|
|
|
|
|
try
BOOL GetCursorInfo(CURSORINFO *ci);
and/or
GetClipCursor() which will give you a rectangle of its boundary
Stephen Kellett
|
|
|
|
|
Hi,
I want to use programatically the win NT command "Net send".
For example to send a message to computer named "Compsrv" i write this like :
c:\> Net send Compsrv Good morning my dear
I use following code to execute this commande under windows with visual C++ :
ShellExecute(NULL, "open", "c:\\WINNT\\System32\\Net send Compsrv Good morning my dear", NULL, NULL, SW_SHOWNORMAL);
BUT it don't work
Can anybody help me
Regards
|
|
|
|
|
I've been working on an app for the last week or two, and everything was going fine until yesterday.
I have an Access database with a handful of tables. I use the following code to (successfully) open the database:
CString sDbName = "igps3.mdb"
CDaoDatabase* m_pDB = new CDaoDatabase();
m_pDB->Open(sDbName);
Next, I open recordsets (created with ClassWizard) for some of the tables. One of the tables is now inexplicably failing in the Open() function, but I don't know why. It honestly just started happening all of a sudden. Here's the code I use in my app:
int nOpenType = AFX_DAO_USE_DEFAULT_TYPE;
CRSDrivers* m_pRSDrivers = new CRSDrivers(m_pDB);
m_pRSDrivers->Open(nOpenType, "SELECT * FROM drivers");
The table exists in the database, and it appears to be okay. I've tried recreating the table from scratch, as well as creating a completely new table. It doesn't metter whether I try to open the recordset first, last, or somewhere in between. All of the other recordsets open without complaint.
Nothing seems to matter. All of the other recordsets open without any problem.
The program stops with a C++ exception in DaoCore.cpp after an attempt is made to open the daotabledef.
This is my first database app and I'm kind of at a loss.
Any suggestions would be appreciated.
|
|
|
|
|
I wanna use the CString class in a non-MFC application, how can i do this? if this cannot be done, what can i use as a substitute? Thanks
|
|
|
|
|
|
I have a LPDIRECTDRAW that is being created fine under debug mode but not under release mode. I am linking ddraw.lib in release and debug modes. When the program runs in release mode, it asserts on my create function:
ASSERT(DirectDrawCreate(NULL,&mDD,NULL) == DD_OK);
Thanks in advance for any suggestions.
|
|
|
|
|
Here is the deal:
I have declared a class object in a function. Then I created a pointer to it right afterwords in the same function. Here is where the problem is. I try to pass that pointer to another function, and i get no errors, yet when i try to look at a data member of the class, i get all kinds of errors. Could someone tell me if this syntax for passing class pointers is correct?
(The class name is army and the object is MyArmy and the pointer to MyArmy is pMyArmy)
Pointer is declared like this:
void make_faction()
{
//creates object
army MyArmy(75, 5, 3000, 5);
//Creates a pointer to army
army* pMyArmy = 0;
//Gives the address
pMyArmy = &MyArmy;
//calling function
game_menu(pMyArmy);
}
Recieving function:
int game_menu(class army *pMyArmy)
{
return 0;
}
Is this the correct syntax? It shows no errors this way, but when i add
cout << pMyArmy->troops << endl;
to game_menu function, get errors.
|
|
|
|
|
I'm not sure about 'class army *pArmy' but normally you pass a pointer to the class by just 'army *pArmy'.
Are you sure the problem is with the pased pointer, and not with the data type you are passing to cout?
What is the type of the troops member? what compile time errors do you get?
|
|
|
|
|
One possible cause is the keyword class in the function declaration for game_menu. I also don't understand why you are creating a pointer?
Why not do it as followed?
void make_faction()
{
//creates object
army MyArmy(75, 5, 3000, 5);
//calling function
game_menu(&MyArmy);
}
int game_menu(army *pMyArmy)
{
return 0;
}
|
|
|
|
|
I want to capture the any portion of a CFormView (displayed or not).
It is possible to get the viewable area with DC tricks but how about non-displayed parts? Where it is stored?
Suha
|
|
|
|
|
http://www.fengyuan.com/article/wmprint.html
|
|
|
|
|
Is this possible. I want to be able to call functions in a DLL writen in C++, from a program writen in C.
If it is possible, is it possible to call functions within a class?
THanks for any help,
Yours
David Wulff
|
|
|
|
|
What font is used by office 2000 and 97 to paint the gui
Joel
|
|
|
|
|