|
==================
The original message was:
Hi,
I have a basic OOP question, I have a class ( a base class, and don't inherits from CObject), and I want to have a constructor with some parameters, I make this, but when I want to compile it without errors I have to add an empty constructor without parameters. Why must I do this ? Have I made something wrong ?
Thanks, Bye ! Braulio
Hi Braulio!
example:
Class A
{
public:
A(int x, int y)
{...}
...
}
int main()
{
A p(1,2); // Call the constructor defined
A p; // incorrect! the default constructor doesn't exist. You have to declare it.
...
}
If you defined your own constructor, you have to respect the list of arguments. Not if you add the default constructor (without argument).
Is your case?
Tchao
Sandrine
|
|
|
|
|
Hi Sandrine !
Good To hear from you here in CodeProject !
I'm not sure what have I made wrong, It was with a class that inherited from a CWinThread, and this class I declare it as a dinamyc class ( I think that is the name ), then I think the problem is that it needs a default constructor, but I'm not quite sure... ( sometimes C++ is a "pretty" maze and the easiest thing make me a little bit crazy).
Ciao !
Braulio
|
|
|
|
|
The VC++ docs say that a default constructor is generated if (and only if) no other constructor
has been defined. Once you define the constructor with parameters, you must also explicitly
define the 'default'constructor if it is needed.
==================
The original message was:
Hi Sandrine !
Good To hear from you here in CodeProject !
I'm not sure what have I made wrong, It was with a class that inherited from a CWinThread, and this class I declare it as a dinamyc class ( I think that is the name ), then I think the problem is that it needs a default constructor, but I'm not quite sure... ( sometimes C++ is a "pretty" maze and the easiest thing make me a little bit crazy).
Ciao ! Braulio
|
|
|
|
|
This is a basic C++ question, not OOP.
When ever you create a class the compiler automatically creates a default constructor and a copy constructor. The default constructor is required if you want to create objects like this:
CFoo foo;
As soon as you create ANY constructor, the compiler requires you to write ALL constructors. In other words, it no longer creates the default constructor for you. That means if you write:
struct Point
{
int x;
int y;
};
Point origin;
...but if you write this...
struct Point
{
int x;
int y;
Point(int x, int y): x(x), y(y) {}
};
...the compiler no longer generates the default constructor...
Point origin;
Point origin (12,45);
Note that a default constructor does not have to take 0 arguments, you simply must be able to call it with 0 arguments. Like this...
struct Point
{
int x;
int y;
Point(int x=0, int y=0): x(x), y(y) {}
};
Now everything's happy again...
Point origin;
Point origin (12,45);
Hope this clarifies more than it confuses!
Cheers,
Eric
|
|
|
|
|
I have found information on how to debug control panel applets using Visual C++ but I have a few question I hope you folks can help me with.
MSDN Knowledge Base article number Q166168 says to set the exectuable for the control panel as;
C:\winnt\system32\rundll32.exe
and the program arguments as;
shell32.dll,Control_RunDLL [path and name of CPL file]
The KB mentions this information is valid for all version of Windows. The instructions seems simple enough but I'm having some problems so my 2 questions are;
1. When I specify the full path to my control panel which would be in the default debug folder as set by Devstudio I can't debug the applet. When I run the project nothing seems to happen, it just exits with no error code or any other indication of a problem. If I specify the path to the Windows system folder and place the applet there it seems to work fine but ... (see problem 2)
2. I can't copy over the control panel once it's placed in the system folder and accessed. It must be kept in memory since Windows doesn't allow replacing the file. I know there is a way to force COM DLL's to unload from memory once they are not used, does anyone know if the same is possible with control panel applets? Perhaps a registry setting or some other mechanism to make the OS not cache the control panel in memory and essentially kick it out of memory.
Thanks in advance for any help ...
|
|
|
|
|
I have a code like this
CString cSQL;
CDatabase db;
db.OpenEx( NULL, CDatabase::forceOdbcDialog );
CRecordset tbl( &db );
cSQL.Format( "SELECT * FROM tablename WHERE ID = %d", nID );
tbl.Open( CRecordset::forwardOnly, cSQL );
try {
tbl.GetFieldValue( "ID", cSQL );
tbl.GetFieldValue( "ID", cSQL );
}
catch( CException* e ) {
char szCause[255];
e->GetErrorMessage( szCause, 255 );
e->Delete();
}
The first GetFieldValue() call gets appropriate value into cSQL variable.
But on the second GetFieldValue() call I get CDBException and
the value of szCause is "" - empty string and m_nRetCode member of
CException object is 100.
What is wrong in this code?
Any help would be very helpful.
Thanks in advance.
Stefan
|
|
|
|
|
The problem is most like caused because you're trying to access the same column's value twice. I haven't debugged into the GetFieldValue code but I do know from experience that you may only retrieve a column's value once and in the proper order. In other words, if you do SELECT *, you must access the columns in the same order as they appear on the table. If you do a SELECT COL1, COL2, ... you must call GetFieldValue for COL1 before calling it for COL2.
I hope this helps,
Alvaro
|
|
|
|
|
ahh, it means you can debug each line. And when it reachs to the end of each function, it runs that function. Or you can step over it and run the function when you meet it. in shorts, it is similar to BORLANDC 3.1 .Can you help me?
|
|
|
|
|