|
|
Sorry you all for bothering on Sunday:
I'm new using C++ and I need to simulate a Social network, but I'm having troubles doing a "member": this
is the code is very simple:
I hava a header called "structs.h"
struct Miembro{
int id;
int activo;
int pass;
Miembro(int a, int b, int c)
{
id = a;
activo = b;
pass = c;
}
};
#include <cstdlib>
#include <iostream>
#include <string>
#include "structs.h"
using namespace std;
int main(void)
{
cout<< "hola";
string nombre;
nombre = "Jorge";
cout <<" "<< nombre << endl;
Miembro memb = new Miembro(1, 1, 123);
}
F:\main.cpp In function 'int main()':
17 37 F:\main.cpp [Error] conversion from 'Miembro*' to non-scalar type 'Miembro' requested
F:\Makefile.win [Error] [main.o] Error 1 (if this is the only error: please check your library includes)
jorgmen
|
|
|
|
|
Because you're creating a new Miembro in this way, all you get back is a pointer to it. You then try to assign this pointer to an object of type Miembro.
Just change it to this:
Miembro *memb = new Miembro(1,1,123);
Make it work. Then do it better - Andrei Straut
|
|
|
|
|
OR, you can just say
Miembro memb(1, 1, 123);
and this will allocate the memb object on the stack. I think this is the recommended way to allocate small objects whenver possible. Objects allocated on the stack are deleted automatically for you when they run out of scope (usually at the end of your function or if-block or whatever). If you allocate an object from the heap then you get a pointer to the heap and you must delete that object via its pointer when you done with it using the delete keyword. By forgetting to delete heap objects your program might continuously 'eat' the memory until you exit the program (this memory waste is called 'memory leak').
|
|
|
|
|
Thaks for your replays:
now i have a new q?
struct Miembro{
int id;
int activo;
int pass;
Miembro(int a, int b, int c)
{
id = a;
activo = b;
pass = c;
}
};
struct NodoMiembro{
NodoMiembro * nextmiem;
NodoMiembro * prevmiem;
Miembro persona;
NodoMiembro(Miembro nuevo){
nextmiem = prevmiem = NULL;
persona = nuevo;
}
};
struct ListaMiembros{
NodoMiembro * lastmember;
NodoMiembro * firstmember;
ListaMiembros(){
lastmember = firstmember = NULL;
}
I can't compile this, I'm having headache because of c++: it says:
4 0 F:\main.cpp In file included from main.cpp
F:\structs.h In constructor 'NodoMiembro::NodoMiembro(Miembro)':
31 27 F:\structs.h [Error] no matching function for call to 'Miembro::Miembro()'
31 27 F:\structs.h [Error] candidates are:
17 1 F:\structs.h Miembro::Miembro(int, int, int)
17 1 F:\structs.h candidate expects 3 arguments, 0 provided
12 8 F:\structs.h Miembro::Miembro(const Miembro&)
12 8 F:\structs.h candidate expects 1 argument, 0 provided
F:\structs.h At global scope:
WHY NodoMiembro can't have a "Miembro xxx" as parameter in the constructor???
|
|
|
|
|
Ooo-ouch!
Those warning messages are pretty nasty. They offered me no help at all in solving the problem. At first I thought it may be a result of being structs, rather than classes - no, of course not. Default access is public instead of private, but it did then get me thinking.
I was writing out the constructors when the idea of default constructors hit me in the face..
Notice in your NodoMiembro definition, you have a variable of type Miembro? Well, have a close look at the way it's defined - It's just Miembro persona;
Just back-up a bit and think what would happen if you tried to instantiate the struct like this in your main() - it would fail miserably.
Here:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
struct Miembro
{
int id;
int activo;
int pass;
Miembro(int a, int b, int c)
{
id = a;
activo = b;
pass = c;
}
};
int main(void)
{
Miembro a;
}
Basically, the fix is to add default constructors to both the the Miembro and the NodoMiembro structs.
Miembro()
{
id=activo=pass=0;
}
and
NodoMiembro()
{
nextmiem = prevmiem = NULL;
}
Make it work. Then do it better - Andrei Straut
|
|
|
|
|
The declaration
Miembro persona; is the same as saying
Miembro persona(); (constructor with 0 arguments) but the only constructor you defined requires 3 arguments
Miembro(int a, int b, int c) so the compiler cannot resolve the reference.
|
|
|
|
|
Chuck O'Toole wrote:
Miembro persona; is the same as saying
Miembro persona();
Just want to mention an exotic exception: If Miembro was a POD type then the two statements had different effects. The first wouldn't initialize the variable while the second would zero initialize. PODs are primitive types - ints, bools, etc... and structs/classes without any explicitly declared constructors/destructor/virtual methods (briefly: C-struct compatible stuff).
|
|
|
|
|
Jorgmen wrote: Sorry you all for bothering on Sunday
Those who don't want to be bothered simply don't login on sunday...
|
|
|
|
|
Not a reply to your question, but just for completeness.
Always prefer initialization to assignment for member variables.
What you've done in the constructor is assignment.
Do the following for initialization instead -
Miembro(int a, int b, int c) : id(a), activo(b), pass(c)
{
}
|
|
|
|
|
Hi,
I am using the Codejock extreme toolkit pro library, to creare docking panes, but I am not sure if this concerns a problem of the mentioned library. So please read the description of the problem.
I am using a simple SDI Doc/View architecture and as main view I am using the CHtmlView class.
In this case if the panes are closed and you are trying to preview them without docking them, you have a repaint problem in the docking's space.
This problem does not seem to appear in other CViews derrived classes.
I am attaching a sample code as well an explanation video with the problem.
Trying to solve this problem, I found out the the WM_PAINT message is not sent to the CHtmlView class except from the very beggining and the very endding.
Any ideas ?
Rapidshare link of the source code
https://rapidshare.com/files/2839795607/HtmlRepaintProblem.zip[^]
You tube video
http://www.youtube.com/watch?v=qhTjzpceiqA[^]
sdancer75
|
|
|
|
|
I use only VC6 environment, si I could not compile your project, but I have a similar problem when I use CHtmlView to show a .pdf file in it, and after few years, I solve the problem :
BOOL CHtmlRepaintView::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}
I hope this help ...
|
|
|
|
|
Thank you for your reply. I have already did that. It does not fix the problem.
I think its a pane dock repaint problem instead of CHtmlView view. I have contacted with the codejock support team and waiting for an answer.
Regards,
George
sdancer75
|
|
|
|
|
How do you paint text on the Desktop like as if your going into Safe Mode in Windows.
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
|
|
|
|
|
Something like this?
"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
|
|
|
|
|
No not like that, sorry I wasn't being really specific, I mean't like this. See where the labels "Safe Mode" on each corner of the monitor or screen, I want something exactly like that, but in order for it take effect once programmed, you need to reboot your computer.
EDIT:
Maybe what you told me is correct, I probably have to get a handle to the desktop of the computer desktop, then "fire in" the code.
Simple Thanks and Regards,
Brandon T. H.
Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst).
Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
|
|
|
|
|
Maybe they use transparent windows onto which is written the text.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
What is the Difference between Variable Definition and Declaration.?
|
|
|
|
|
AFIK, you can only declare a variable, but you can both declare and define a function.
For functions, the declaration is what you put in the header file:
BOOL Function( DWORD A, CString& B );
and the definition is where you put the body of the function - the code that makes up the function:
BOOL Function( DWORD A, CString& B )
{
A += 1;
B = "Hello World";
return TRUE;
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You can declare a global variable with the extern keyword. Misleadingly many people say "variable declaration" however most of the "variable declarations" are actually variable definitions. Definition == declaration + storage.
definition - test.cpp:
int g_MyVariable;
declaration - test.h:
extern int g_MyVariable;
you can use the global variable anywhere by including test.h
Note: Using an extern variable as communication between compilation units is a bad design. Not using it is laudable!
|
|
|
|
|
Ah, thank you for correcting me.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The variable declaration specifies the type and the link-name of the data. You usually put declarations to header files. When a .cpp file compiles and includes a header that declares a variable then that .c/.cpp file can use the variable despite the fact that the location of the variable isn't known because it can generate code that uses the specified type as needed and the link-name of the variable is known so later you can link the generated object file of your .c/.cpp to the object file of another .cpp that actually contains the data. A variable definition specifies the type and the link-name of the data like the declaration, but it also specifies the actual location of the data. The variable is located where you put the definition. For a variable you can use only one definition in one of your .c/.cpp files, your variable will be located in the generated object file of this .c/.cpp file, but you can have many declarations in other .c/.cpp files by including in a header with the declaration to many .c/.cpp files. This way the generated object file of the other .c/.cpp files will just have a reference by name to the defined variable if you actually used the declaration where you included it.
|
|
|
|
|
int x;
int x = 5;
"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
|
|
|
|
|
|
Hi, dear all,
I have a MFC application created in C++ 6.0, it works fine in Window XP. When run this application in Window 7, if the dialog has progressbar on it, this dialog cannot be launched, but if you remove this progressbar or for dialog without progressbar, everything is fine.
But no all Window 7 computers have this error, only very few computer have this problem.
Is there anybody having this issue? or any idea?
Thanks!
|
|
|
|