|
m_pMainWnd is not set by MFC. It is provided to be used in your code. Common usage is to assign the address of your main frame window (or the main dialog with dialog based applications) upon creation in InitInstance() :
CMyApp::InitInstance()
{
...
CMainFrame * pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = static_cast<CWnd*>(pMainFrame);
...
}
Purpose is to have access to your main frame class from all modules of your app:
CMainFrame * pMainFrame = static_cast<CMainFrame*>(AfxGetApp()->m_pMainWnd);
|
|
|
|
|
ok so i am given the goal to read the disk file and separate each line into three fields of text, idnum, Name, absences and either store the data into three parallel arrays, or a linked list of objects the professor is going to give us a alternate file of student info. i was going to do a linked list but i am unsure of how to make it attached to a disk file. And how to implement it as we only spent one class on linked lists. I will admit i dont know much about linked lists. i know the basic formatting of them and ive read everything that my book covers but the information im seeking either im not comprehending or is unavailable in it. Being the goal of this project i figured a linked list would be the best course of route
all info and input is greatly appreciated here is what i have so far for the program as i said linked lists are not my strongest area
ramdom is the name of the text file btw
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
{
struct Student;
int idnum;
student *next;
}
int idnum[10000000];
char name[10000000];
double absence[100000000];
ifstream infile("random.txt");
int search_idnum;
char random[50];
ofstream out_stream;
cin.getline(random, 50);
out_stream.open(random);
if (infile.fail())
{
cout << " unable to open the file" << endl;
return 1; }
else
{
cout << "Please enter the student id number: ";
cin >> search_idnum;
random >> idnum;
if (int idnum == int search_num)
{ random >> idnum >> name >> idnum;
cout << "For the idnum " << idnum << " the \n"
<< "last name is: \n" << name << "and the "
<< "absences is: \n" << absences;
}
else
{ {
cout << "I could not find the student number.";
system ("pause");
}
return 0;
}
here is the info
Quote:
4215534 Austin 3
5551298 Bailey 3
6224649 Balovich 4
6502286 Bates 4
8448936 Bettencourt 2
2883903 Blackburn 9
6752376 Boucher 1
3564698 Brown 2
6373150 Duncan 2
6375372 Estrada 1
modified 18-Dec-12 1:14am.
|
|
|
|
|
You certainly do not need to start with 10,000,000 element arrays reserved in memory. You also seem confused about how to handle data streams. You have opened an input stream and then an output stream, but you never use either of them. You are also trying to use a character array as a stream.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I know if I have a class like that
class A
{
shared_ptr<SomeType> data;
}
I don't need to declare a destructor, as the compiler will automatically write one for me that take care of everything.
But what if I have a resource without a destructor, such as a handle.
I need to implement a destructor
class A
{
shared_ptr<SomeType> data;
HANDLE wndobj;
~A() {
CloseHandle(wndobj);
}
}
Do I need to handle all variable? or only those without destructor (i.e. wndobj)?
I.e. what of data?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Good question, if your class allocated the pointer, but shared it with other classes, then you will need to reference count it and olny delete the allocation when the last reference is removed.
==============================
Nothing to say.
|
|
|
|
|
it's a shared_ptr! the reset method is here for that, it decrease ref count.
so, if I get you right, when I declare my own explicit destructor I do need to call all the destructor of my properties? but I didn't use new... (as in ComPtr<t> that I get through a query) mmm .. I guess I set those to null..
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Super Lloyd wrote: but I didn't use new...
That has nothing to do with it.
The use of 'new' is specific to a certain kind of finite resource (memory).
Your class on the other hand must manage ALL of the resources that it owns. So it must clean it up.
|
|
|
|
|
I wrote a little test program to answer all my questions!! :P
To answer the one on this page, no need to call .reset()!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I think that what Eric meant above was that if you share the resource handle through the shared_ptr then you should not CloseHandle prematurely, when others still are using it. Thus you need to examine the ref count before CloseHandle, or else you will have invalid objects.
Life is too shor
|
|
|
|
|
Errr, we're talking about the destructor and said shared_ptr object is about to be destroyed - it doesn't have to be reset! Would be a dumb kind of smart pointer if you still have to tell it to decrease the reference before destroying it...
|
|
|
|
|
A little test program clarified everything! ^^
All non pointer member's destructor get called at all time, whatever else might be...
I was just not sure initially! ^^
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Yes, I was talking generally and as you say the shared_ptr class does this for you so no need to worry about it.
As for things like handles, in your example, it is best to call a close on them before your class destructor is called, ie, do your tidy up as early as you can.
==============================
Nothing to say.
|
|
|
|
|
The destructor will be called on data, so there's no need to call reset.
Steve
|
|
|
|
|
Thanks!
Indeed I though of writing a test program and found that out too!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Helo i want to implement fuzzy logic code in C++ and i am new in it can any one help me plz i need urgent help
|
|
|
|
|
This is not a good question as you have really not described what you are trying to do. Try a Google search first and read some information on the subject.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
i have done alot of search on it and i need to implement it immediately.
|
|
|
|
|
What does that mean? Do you think that there is a simple formula or algorithm for Fuzzy Logic?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
no there is proper procedure for that but what is your clever thinking actually i have to make something new i am implementing fuzzy logic to improve movement of my robot as there is so much disturbed walk of robot in through dead reckoning code so i have to remove it and then i have to generate something new if u can help i'll be very thankful
|
|
|
|
|
Sorry, buy I have no idea what you are doing or what code you are using. If you want help with specific issues in your code then you need to explain exactly what your problem is. As I said before, this is not just a matter of adding a simple formula or algorithm.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
i am implementing fuzzy logic on robot to make its drive straight
|
|
|
|
|
Your request is wrong on so may levels. For starters, AI/fuzzy logic is not a beginner's subject matter, especially if they are also learning C++.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I know a company you can work for whose code seems to be nothing but fuzzy logic.
|
|
|
|
|
robot29 wrote: Helo i want to implement fuzzy logic code in C++
You need to drink quite a lot of alcohol to achieve this. And then write a lot of code, very fast.
Next day you will look at what you wrote, and it wont make sense and might work...
|
|
|
|
|