|
Hope this code better explains what my I am trying to do
CLass A
{
private:
int c;
char d;
public:
int e()
{
return c;
}
}
Class b
{
private:
public:
int f;
f = getc() // compile error because the compiler wouldn't
{ // know what instance of e I want unless I declare it
e(); // static right ????
}
}
|
|
|
|
|
Hey!! What are you trying to do??
Class b
{
private:
public:
int f;
f = getc() // compile error because the compiler wouldn't
{ // know what instance of e I want unless I declare it
e(); // static right ????
}
}
f = getc();
e();
And finally, take a good c++ book it's all there in the third page.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Thank you
I understand as you can tell I Am just starting to code in OO
|
|
|
|
|
ok no probs! But what I suggested was that you should start from basics then look at complex stuff otherwise you'll waste a lot of time getting puzzled.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
I think I am begining to understand
A class is really a typedef not real storage only when you declare that object then storage is allocated
If you have a object you want to modify e,g, add you derive that Class
you can access private data members in the derived class by writting your own constructer for it
When you derive it as you stated and use a function/data from derived object the compiler is not confused which instance it the this-> instance
I think I have a better understanding
|
|
|
|
|
VA_ wrote: And finally, take a good c++ book it's all there in the third page.
"The third page" ?!
Maxwell Chen
|
|
|
|
|
Yeah the first two being the "Contents" and "Preface"
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
By chance you are talking about something like :
#include <iostream>
using namespace std;
class one
{
private:
int x;
public:
one(int x_in)
{
cout<<"\n Created only once";
x = x_in;
}
void print()
{
cout<<"\n"<<x;
}
};
class two
{
int y;
public:
two()
{
y=10;
}
void printTest()
{
for(int i=0;i<=10;i++)
{
static one oneObj(y);
y++;
oneObj.print();
}
}
};
int main(int argc, char* argv[])
{
two twoObj;
twoObj.printTest();
return 0;
}
Otherwise you just need a singleton.
ReadHere[^]
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Hello Gurus
I've stack in my try to convert this:
CDialog *m_Dialog[2];
Into this:
CArray<CDialog *, CDialog *> dlgArray;
I just want to be more flexible.But when I use it by this way:
for(int nCount=0; nCount < m_nPageCount; nCount++)<br />
dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
I receive an exeption. I think that my mistake is in the template, but I can't solve it. Thanks.
|
|
|
|
|
I don't know if the mistake is in the template. It is not apparent in the posted code. I suggest you to post the exception received and other relevant code (for instance CArray elements assignment.
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.
[my articles]
|
|
|
|
|
For debugging this kinda code , First do like :
<br />
for(int nCount=0; nCount < m_nPageCount; nCount++)<br />
{<br />
dlgArray.GetAt(nCount);<br />
}<br />
This confirms that you can iterate through the container without any problem. If it runs fine, then try :
<br />
for(int nCount=0; nCount < m_nPageCount; nCount++)<br />
{<br />
dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());<br />
}<br />
Then post the actual error message.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Because the info you provided is not enough, I can not be sure that you are doing correctly. Here is the check list for you.
1) One must add data elements into an array container, then he can enumerate the elements in the container. Getting elements from an empty container would result in access violation.
2) Before invoking CDialog::Create , the pointer of type CDialog* needs to be new -ed.
3) The for loop shall check the actual size of the array by calling CArray::GetCount . That is,
for(int nCount=0; nCount < dlgArray.GetCount(); nCount++)
Maxwell Chen
|
|
|
|
|
First Thank you all for replays. I'm still stack. So I will give you additional information . Please excuse my English I still learning. First I create the Array in my header file with template, like this:
CArray<CDialog *, CDialog *> dlgArray;
Then in my .cpp file I add some data:
dlgArray.Add(new CDlgSettings());
And I want to use this data by this way:
m_nPageCount = 1;<br />
for(int nCount=0; nCount < m_nPageCount; nCount++)<br />
dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
My idea is to use the above code to insert dialog into Tab Control. The project is compiling without error, but when i try to open the dialog which contains the Tab Control I receive the folowing error.
Asseration Failed!<br />
MyProgram: File afxwin2.inl, Line 262
modified on Sunday, January 06, 2008 3:12:48 AM
|
|
|
|
|
babamara wrote: dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
1) Make sure that m_DialogPages[nCount] refers to a valid dialogbox resource ID.
2) Let's say, dialogbox A has a tab control. In the implementation of A, it creates some child dialogboxes. I think that the second argument for CDialog::Create should be this , not GetParent .
3) Make sure the dialogboxes to be held in the tab control have the property "child window ".
Maxwell Chen
|
|
|
|
|
Thank you. I change GetParent with this and this solves the probelm. Now I am going to check why the dialog are not shown in my Tab Control.
|
|
|
|
|
babamara wrote: Now I am going to check why the dialog are not shown in my Tab Control.
Try CDialog::ShowWindow(SW_SHOW) .
Maxwell Chen
|
|
|
|
|
I use this function
void CPropertyTabControl::ActivateTabDialogs()<br />
{<br />
int nSel = GetCurSel();<br />
if(dlgArray[nSel]->m_hWnd)<br />
dlgArray[nSel]->ShowWindow(SW_HIDE);<br />
<br />
CRect l_rectClient;<br />
CRect l_rectWnd;<br />
<br />
GetClientRect(l_rectClient);<br />
AdjustRect(FALSE,l_rectClient);<br />
GetWindowRect(l_rectWnd);<br />
GetParent()->ScreenToClient(l_rectWnd);<br />
l_rectClient.OffsetRect(l_rectWnd.left,l_rectWnd.top);<br />
for(int nCount=0; nCount < m_nPageCount; nCount++)<br />
{<br />
dlgArray[nCount]->SetWindowPos(&wndTop+21, l_rectClient.left,<br />
l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(),<br />
SWP_HIDEWINDOW);<br />
}<br />
dlgArray[nSel]->SetWindowPos(&wndTop+21, l_rectClient.left,<br />
l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW);<br />
<br />
dlgArray[nSel]->ShowWindow(SW_SHOW);<br />
<br />
}
|
|
|
|
|
babamara wrote: dlgArray[nCount]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(),
SWP_HIDEWINDOW);
1) Which target does &wndTop+21 point to?
2) Since you've invoked CWnd::SetWindowPos with the flag SWP_SHOWWINDOW , there is no need to invoke CWnd::ShowWindow(SW_SHOW) again.
Maxwell Chen
|
|
|
|
|
babamara wrote: SetWindowPos(&wndTop+21
?!?
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.
[my articles]
|
|
|
|
|
Hi,
I have the following class declared:
// header file
class classA
{
protected:
static classA *a;
static void setClassA(classA *pa);
}
// *.cpp file
#include "classA.h"
void classA::setClassA(classA *pa)
{
classA::a = pa;
return;
}
This code compiles just fine but it does not link.
The error I get is:
unresolved external symbol "protected static class classA *classA::a"
|
|
|
|
|
You need to define the static member pointer. Write the following statement in the source (*.cpp ) file
classA * classA::a = NULL;
BTW you missed a semicolon at the end of the class declaration.
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.
[my articles]
|
|
|
|
|
Thank you for the quick response. It works now.
I have been doing some research in the meantime.
I am not sure if I understand why I have to do this extra reference.
Is it because static limits the visibility of the variable to the include <.h> file?
|
|
|
|
|
jupiter1000 wrote: I am not sure if I understand why I have to do this extra reference.
Is it because static limits the visibility of the variable to the include <.h> file?
According to MSDN [^]
Static data members are not part of objects of a given class type; they are separate objects. As a result, the declaration of a static data member is not considered a definition. The data member is declared in class scope, but definition is performed at file scope. These static members have external linkage
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.
[my articles]
|
|
|
|
|
Hey, I use my printer dc to paint some text and graphic to my printer. I use MM_LOMETRIC as Mapmode because of the easy way of positioning. Now I have a big problem to print bitmaps. All bitmaps are mirrowed (around X-axis).
I use the following code to paint the bitmap:
<br />
<br />
<br />
....<br />
CBitmap *pBitmap = new CBitmap();<br />
HBITMAP hBitmap;<br />
hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),szPathToBitmap,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);<br />
pBitmap->Attach(hBitmap);<br />
...<br />
<br />
<br />
<br />
CRect reRect;<br />
<br />
reRect.left = 10;<br />
reRect.right = 300;<br />
reRect.top = -100;<br />
reRect.bottom = -1000;<br />
<br />
CDC dcMem;<br />
BITMAP bm;<br />
<br />
pBitmap->GetBitmap(&bm);<br />
dcMem.CreateCompatibleDC(pDC);<br />
dcMem.SelectObject(pBitmap);<br />
pDC->BitBlt(reRect.left, reRect.top, bm.bmWidth, bm.bmHeight, &dcMem,0,0, SRCCOPY);<br />
<br />
<br />
What's wrong, and how could I fix it?
|
|
|
|
|
Maybe try
pDC->StretchBlt(reRect.left, reRect.top, bm.bmWidth, -bm.bmHeight, &dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|