|
It isn't a bug, it's feature. More likely a side effect, though.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
you mean accessing a virtual protected derived class member using a base class pointer is a feature?
|
|
|
|
|
Yes, it is a side effect of polymorphism.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Its the normal behaviour of virtual members, the access control is compile time restriction it depends on which function you call. see this, [Access to Virtual Functions^].
|
|
|
|
|
followait wrote: protected: virtual ~D(){}
Did you success in creating an object of the class D in another class or global function?
|
|
|
|
|
|
D objD;
can't be compiled, and
D *p=new D();
delete p;
also can't be compiled.
However,
B *p=new D();
delete p;
works.
I know, it should be called through the right interface.
Thanks.
|
|
|
|
|
Obvious that, that are the difference you can expect from the protected keyword, you cannot have obj of D allocated other than through new operator you can delete only through B and it remains correct only if B has virtual destructor.
I mean protected keyword does its job expected.
|
|
|
|
|
Hi,
Any one know which message Windows sent to Explorer windows indicating a new file is created so that it must refresh and indicate the new changes in the Explorer window.
thanks
Nitheesh
|
|
|
|
|
Nitheesh George wrote: Any one know which message Windows sent to Explorer windows indicating a new file is created so that it must refresh and indicate the new changes in the Explorer window.
I am not sure whether the explore is getting any message. May be the explorer is watching the changes in the current directory using ReadDirectoryChangesW() or using the FindFirstChangeNotification() function.
|
|
|
|
|
|
Hey everybody,
I got problem with prototype. I do have 2 classes both inherited from CDialog. And these two have pointer, which points each other.
It seems smt like this:
<br />
CChild : CDialog<br />
{<br />
CMain* parent;<br />
<br />
void doSmt();<br />
};<br />
<br />
CMain : CDialog<br />
{<br />
CChild* child;<br />
<br />
void doSmt();<br />
};<br />
I got a header file which includes Child first and Main after. OK now my problem is
if I do not write class prototype of Main in the header file before including Child header file it gives me error: CMain undeclared identifier which makes sense.
But, when I do write prototype:
<br />
class CMain;<br />
<br />
#include "CChild.h"<br />
#include "CMain.h"<br />
then it gives me use of undefined type CMain at the line which I call a function of CMain from CChild class.
And when I do (try to) write a prototype of DoSmt function:
<br />
class CMain;<br />
void CMain::doSmt();<br />
<br />
#include "CChild.h"<br />
#include "CMain.h"<br />
gives me the same error at line where I define function prototype.
So I guess the question is, how can I define prototype of my class function
Thanks....
|
|
|
|
|
dehseth wrote: class CMain;
#include "CChild.h"
#include "CMain.h"
then it gives me use of undefined type CMain at the line which I call a function of CMain from CChild class.
What is the source file compiling (whenever this error occurs)?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
source code is a lil bit long it makes more confusion if I paste it in here.
this error occurs during compiling:
I have 2 classes which points each other with pointers.
During compile I include child.h first and main.h later.
Since child class includes a main class pointer in itself it asks for the class. So I need to write a prototype for mainclass before including child class. When I write class CMain; it asks for Main class functions, cause child class calls function of main class. And here my problem starts cause compiler says undeclare identifier of CMain class...
So how can I declare a working prototype of CMain class to compile whole code
|
|
|
|
|
Deferred declaration (the one you used for class CMain should work, but you've define methods containing references to CMain methods inside CChild source (not inside the header).
for instance:
class A;
class B
{
A * _pA;
B(pA){_pA=pA;}
void DoSomethingWithA();
};
void B::DoSomethingWithA()
{
_pA->DoSomething();
}
should work, while
//FILE: B.h
class A;
class B
{
A * _pA;
B(pA){_pA=pA;}
void DoSomethingWithA()
{
_pA->DoSomething(); // ERROR, UNDEFINED REFERENCE
}
};
shouldn't.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
ok! I got a lil bit confused right now... You sound right. I need to include header files.. Well I did writye the source code bottom of header files which is wrong, I get that now!
Now my problem continues... These are the files I have got:
Main.cpp
Child.cpp
MSFLexGrid.cpp
Application.cpp
I include header files in each of them correctly. Compling each one one by one does not create any errors. But when I do Build, if says
error LNK2005: "int __cdecl getSize(char *)" (?getSize@@YAHPAD@Z) already defined in App.obj
cause it's already included in cpp file... So Do I have to write
#ifndef
directives to each header file
How can I build without having any linker errors??
Thanks...
|
|
|
|
|
How did you define such function? Where?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
ok I have solved the problem!
I've got linker error problems because I am defining Message Map declerations in header file.
I just move BEGIN_MESSAGE_MAP parts into cpp file and my problem is solved!
Thank you for your help!
|
|
|
|
|
you need the forward declaration in the declaration file, say in CMain.h,
declare
CMain.h:
class CChild; // forward declaration.
CMain : CDialog
{
CChild* child;
void doSmt();
};
remove the forward declaration in the cpp(I Suppose)
CMain.cpp:
dehseth wrote:
class CMain;
#include "CMain.h"
#include "CChild.h"
void CMain::doSmt()
{
}
#include "CChild.h"
#include "CMain.h"
|
|
|
|
|
didn't worked.....still says undeclared identifier..
|
|
|
|
|
yes that can happen for the other CChild.cpp,
if you understand what forward declaration can do, you can alone fix the problem.
if you want from me, say what are the files cpp, h and how you declare
|
|
|
|
|
Hello ,
I use this section to write some code in a file
f.Open(_T("file.log"), CFile::modeNoTruncate | CFile::modeWrite);
if(f!=f.hFileNull)
{
f.SeekToEnd();
}
else
{
f.Open(szFilename, CFile::modeCreate | CFile::modeWrite);
}
CArhive arStore(&f, CArchive::store);
arStore.WriteString(_T("message");
It works fine like this. But I want to make a class that writes the file.
In .h I have :
private:
CFile f;
CArchive arStore;
And I have a method to write an open file.
I encounter a problem in constructing the arStore object. (ERROR: CArchive not apropiate default constructor available)
This like is the problem : arStore(&f, CArchive::store);
I think that there is a method like Open for CFile but I don't find it.
Tnx for the help
|
|
|
|
|
mihai123 wrote: I encounter a problem in constructing the arStore object. (ERROR: CArchive not apropiate default constructor available)
You can use the Initialization list.
eg:
class Test
{
private:
CFile f;
CArchive arStore;
public:
Test():arStore(&f, CArchive::store)
{
};
};
|
|
|
|
|
tnx it works
|
|
|
|
|
Hi,
How can I add skin to my project?
|
|
|
|