You need to execute that code through the debugger to see exactly what is happening. I tried to reproduce it and it was passing blank parameters in to the method. I suspect that the problem is where you are reading values from the input file.
That method is modifying both variables nome_cifrato and cognome_cifrato inline, and you then call setNome and setCognome. But you have already modified the names so you do not need to call the setter methods. I think you need to look more closely at the design of this application and remove some of the redundancies.
That method is modifying both variables nome_cifrato and cognome_cifrato inline, and you then call setNome and setCognome. But you have already modified the names so you do not need to call the setter methods.
I didn't see it, I get confused writing the code, probably I inteded to use local variables to build cifrated name and surname.
passing the address to "cod". And about this, I understood the reason (Greg Utas was right about the rules but didn't apply to the real problem because i did not need to change the strings passed to the methods but the instance of the class itself). But now there is another behaviour that confuses me :
string nom = nome_cifrato;
string cog = cognome_cifrato;
cout<<" nome cifrato "<<nom;
cout<<" cognome cifrato "<<cog<<endl;
because in the first version it was just printing nothing. Now it prints correctly. I just tried without a real knowledge behind, only some kind of sensation but I don't understand why it didn't work before and why it works now.
Anyway thanks for all the efforts/suggestions. I am just starting with c++ in order to help my children in their school exercise.
I am just starting with c++ in order to help my children in their school exercise.
Well, I am sorry to have to say this, but what you have created is not a good example of C++ code for them to follow. The two static methods cod and decod serve no purpose other than to call the actual methods of the anagrafica class. So they are totally redundant; you could call the codifica method direct from main. There are a number of other issues that look incorrect to me but I do not have time to teach you C++.
That was a request (strange to me too. Exercise : implement a function that calls the methods ..., not directly in the main. Could also be that it was some type of cut and paste from other exercises so some error in the exercise definition ). As I said I am starting too so I do what I can and for that reason I am writing here otherwise why should I do this (to ask a forum)? Then I think that everyone is doing something makes mistakes some for distraction (some I did here) and some for poor knowledge (and also here).
But going straight to my last question is there an explanation?
I have no idea where that question came from or what it actually says. But I would assume that if you want an explanation then the place where you found it is the best place to ask. The forums here are more for help in diagnosing and fixing specific problems. There are other sites that offer well written tutorials, such as Learn C++ – Skill up with our free tutorials[^] and C++ Tutorial[^].
A project about cars, a library, a pharmacy, a clinic, or ....Etc
Since this project has more than one class
In the project, it has at least 3 properties ( attributes) and contains functions (methods )
Yeshti applied all the concepts of oop in this project
We build at least 5 classes in the project and in each class we apply complex relationships to it and apply the uml scheme to it
It is necessary that in a project report we explain in the report the characteristics of the project, the functions and the goal of the project ,
We use the comments in the editor, in which we explain the description of the functions and the action of each function with an appropriate expression .
The functions we convert to string, and use the principle of inheritance with the determination of private and public variables . It must be in the builder function and the copier function .
And we use get and set
We are getting your rants, and you are not getting what you want, because you keep asking the same questions and people don't keep track of someone who goes by just a "number".
The bottom line is: This is NOT a "bluetooth" (expert) site, and all your ranting won't change that. If there is one here (an expert), he may not care to contribute under the circumstances; and that's their choice.
You may not realize it, put people do not knowingly volunteer a "wrong" answer. If you don't like the answer, or have heard it before, keep it to yourself. You create a thread; expect different answers; deal with it (and this post).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
1. I thought 'foreach" was a C++ "feature" - in QT doc they call it macro "Q_FOREACH" -
not sure which way is up...
2. The syntax
foreach(QString str, StringArray[MAX_ARRAY])
is the one which "assigns" INDIVIDUAL char to str
I need the entire string of specific array , not the char
Irregardless if it is a macro or not
what is correct syntax to get the entire string USING "foreach" ?
From the description - it is an iterator and the object of iteration is vaguely described -
sort of "automatic". .
If I iterate QString and expect QString -
one usage gives me full string - from start to last new line
and another gives me INDIVIDUAL characters- one by one.
2. The syntax
foreach(QString str, StringArray[MAX_ARRAY])
I cannot find the StringArray class in QT documentation. Do you meant QStringList Class | Qt Core 6.3.2[^]?
On the other hand, if you use a (C-like) array of QStrings, then you could use the C++ range-based for.
"In testa che avete, Signor di Ceprano?"
Thanks, after few RTFM I finally came to realize it is QT macro. If I knew that such I should have study the macro and realize I was expecting wrong result. After all this I think it has , the QT macro, its place , but it essentially is a replacement for standard C "for loop ".
I am dealing with a school exercise in c++ within an Ubuntu virtual machine. I have a header.h with the class, a header.cpp with the method implementation, a main.cpp and i compile it (main.cpp includes header.cpp which includes header.h) with the following: g++ main.cpp -Wall -o main (from ubuntu terminal). Then I run it and that's ok.
I then tried to import the same exercise in visual studio 2019 creating at first an empty c++ project. After I tried with a CMake project. In both cases compiler/linker return error LNK2005 relevant to all the method implementation saying that they are already defined in main.cpp.obj.
I would attach the complete project in both versions (Ubuntu side and vstudio19 side) but I do not see how. Regards
main.cpp includes header.cpp which includes header.h
This is probably the source of your problem. Visual Studio is probably compiling header.cpp and creating a separate object file, then compiles main.cpp, which includes header.cpp, and so creates two copies of the methods defined in header.cpp. In general it is a mistake to #include a cpp file in another cpp file. You main.cpp only needs to include header.h, which should only provide a declaration of your class. You would then compile main.cpp and header.cpp separately.
In the above example, the -c option to g++ tells the compiler to only produce an intermediate object file (e.g. a .o file), and not try to produce an executable. The third line creates the final executable, and includes all the system libraries and startup code needed for the executable.
Thank you, your answer is clear. Now the point is that I am not used at all in c++ compiling/linking and I am not used to VS configuration of compiler and linker, so I ask if you could help. Correct me if I am wrong : (we are within VS2019)
1) a create a new cc++ emty project
2) Add main.cpp , header.cpp and header.h to the project.
3) Include header.h in main.cpp
Now from the VS2019 environment, how do I compile separately main.cpp and header.cpp? I guess I have to compile header.cpp before. Isn't it? But how do I do that?
And then, how do I compile main.cpp and how the VS2019 knows, while compiling main.cpp, where to get the method implementation i.e. the header.obj?
Last Visit: 31-Dec-99 19:00 Last Update: 28-Nov-22 21:37