|
I figured it out. It was a LAME mistake!
|
|
|
|
|
Intellisense shows that I can access myPlines (myGroups[i]->)... why can't I access myVerts? (see bold code below). Shouldn't this work like a nested structure? Thanks for any help.
class Group
{
public:
list < Pline * > myPlines;
void addPline(Pline *p) {myPlines.push_back(p);}
}
class Pline
{
public:
void addVert(CPoint *v) {myVerts.push_back(v);}
void removeLastVert() {myVerts.erase(myVerts.end());}
list < CPoint * > myVerts;
};
**********FormView.h****************
Group *myGroups[10];
*********FormView.cpp ***************
FormView::OnDraw(CDC* pDC)
{
pDC->Polyline(myGroups[i]->myPlines[k]->?
}
**********************************************************
**********************************************************
I had hoped it'd work like this:
*************** Nest.h *******************************
typedef struct {
int *x1;
} One;
typedef struct {
One *x2;
} Two;
typedef struct {
Two *x3;
} Three;
class Nest
{
public:
Nest();
Three myNest;
virtual ~Nest();
};
************** Nest.cpp *********************************
Nest::Nest()
{
myNest->x3->x2->x1 = 10;
}
|
|
|
|
|
The STL list, which you have used for myPlines, does not overload the array access operator, []. If you need to access it using this operator, you should use a vector instead, otherwise you should be iterating through the list, rather than trying to retrieve an item at a specific index.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Hi,
I have a function
bool equal(double val)
{
if(val == 0.0) return true;
else return false;
}
if val = 0.0;
function will return true
if val = 0.0000000000000001;
function will return false
Is there a way to set a tolerance so that 0.0 == 0.000000000000001 -> true?
Thanks
Everything's beautiful if you look at it long enough...
|
|
|
|
|
Sure, you can try something like:
<br />
bool equal(double val)<br />
{<br />
if(fabs(val) < 0.00000000001) return true;<br />
<br />
else return false;<br />
}<br />
|
|
|
|
|
|
Thanks for the link. It looks like a good and efficient solution.
John
|
|
|
|
|
Hi all
where can I find a combobox that displays the shell tree (like the one in the Windows explorer)? I need it in my MFC app
|
|
|
|
|
One solution is CTreeCtrl.
Kuphryn
|
|
|
|
|
|
Hi !
I created a FrameWnd and attached a tool basr to it, but when I scroll the window, the tool basr moves with the window and goes away...
Any way to fix it ?
Shay
|
|
|
|
|
I am writing a filter for an array of classes. I want users to type in the filtering parameters as text in a script file. E.g.
Price > 10;
Country = "US";
Currency = "CAD";
Years <= 5, etc.
The c++ code should then create an unfiltered array, read this file, and then filter the array. One way of doing this is to come up with a bunch of if statements:
if( sLHS == "Price" )
{
if( sSign == ">" )
if( GetPrice( ) > 10 ) bPassed = true;
else if( sSign == "<" )
if( GetPrice( ) < 10 ) bPassed = true;
...
}
...
if( sLHS == "Years" )
{
if( sSign == ">" )
if( GetYears( ) > 5 ) bPassed = true;
....
}
and so on.
With many parameters to choose from I am going to end up with a thousand of if statements. I AM LOOKING FOR AN EASIER WAY AND I NEED YOUR HELP.
It would be really nice if I could come up with an array of something like this:
Price GetPrice( );
Country GetCountry( );
Years GetYears( ), etc.
then go through the array, find the corresponding item in the left column and then call a specific function in the right column based on its name. BUT HOW CAN I DO THIS AT RUN TIME?
Any thoughts are appreciated.
Thanks
|
|
|
|
|
what you could do is come with a structure
typedef struct {
string name ;
static void funcPointer ;
}REQUEST ;
Now add a function to just compare the name and for a match call the static function in the class .
|
|
|
|
|
Thanks for the reply. A few additional questions:
- How do I get a pointer to a function?
- How do I call this function after I have the pointer?
- What if I need to pass certain parameters to the function?
Thanks
|
|
|
|
|
The following example shows how to use the standard library to sort an array of Data objects. You can then use find() and find_end() to find the first and last iterators within the container. It is possible to do this with arrays but the code was easier to write with vectors.
The code for handling function pointers is in the DataSorter class. This solution is extensible to any number of properties. If you need to pass in parameters have a look at binders in the STL or in Boost.
Good Luck
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
class Data
{
public:
Data()
: price_(0), years_(0)
{
}
Data(int price, int years, const string& country, const string& currency)
: price_(price), years_(years), country_(country), currency_(currency)
{
}
int getPrice() { return price_; }
int getYears() { return years_; }
string getCurrency() { return currency_; }
string getCountry() { return country_; }
private:
int price_;
string country_;
string currency_;
int years_;
};
template<class T>
class DataSorter
{
public:
typedef T (Data::*Method)();
DataSorter(Method m)
: m_(m)
{
}
bool operator()(Data& a, Data& b)
{
return (a.*m_)() < (b.*m_)();
}
private:
Method m_;
};
int main()
{
vector<Data> v;
v.push_back( Data(10,1,"US","US") );
v.push_back( Data(11,2,"Australia","AUD") );
v.push_back( Data(9,4,"France","Francs") );
sort(v.begin(),v.end(),DataSorter<string>(&Data::getCountry));
for(int i = 0; i < v.size(); i++)
{
cout << v.at(i).getCountry() << endl;
}
return 0;
}
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I need C++ source code / examples / docs on disk defragmentation. Do you know any?
Regards,
BB
|
|
|
|
|
|
You emailed about Win9x... I'm sorry I do not have a source for that...
John
|
|
|
|
|
Thanks anyway for the NT clue!
Regards,
BB
|
|
|
|
|
I wanted to post the comment about win98 here hoping that someone would reply. Its better to post questions here than to email because there is a chance that someone else will see your post and have an answer...
John
|
|
|
|
|
Hi,
I have a window that inherits from CFrameWnd.
I did some drawings inside and I want to clear the window and start from a clean one,
How do I do it ?
Shay
|
|
|
|
|
I'm not sure what you want to do.
how/where do you paint ? You could "empty" the the view with a FillRect on the entire view area.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
I already found it:
this->Invalidate (true).
But I have another one:
I created a tool bar on my FrameWand but when I scroll it, the tool bar scroll with it how can I make it stay there ????
Thanks
Shay
|
|
|
|
|
I have a little function which reads from a file:
int Read(int iFile, char *szData, size_t iBytes)
{
int iReadThis = 0;
while (iBytes > 0)
{
iReadThis = read(iFile, szData, iBytes);
szData += iReadThis;
iBytes -= iReadThis;
if ( iReadThis == 0 )
return 1;
}
return 0;
}
and I am trying to read through an entire file, say 1 MB at a time or 4 bytes at a time; In either case, I can not read through the whole file because the functions returns 1 at some point and it's not the end of the file either (checked the position of the file pointer). What could be the reason for this and what is a workaround for it?
|
|
|
|
|
1. check for error
georgiek50 wrote:
if ( iReadThis == 0 )
{ //use ::ferror here to check if it is an error
return 1;
}
it is also helpful in debug to put "@err,hr" into watch window, that way you can observe system error.
2. Where did iBytes come from?
3. how did you allocate szData?
|
|
|
|