|
Ok you are right saying that
Richard MacCutchan wrote: 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.
But problem was in this function within the main
void cod (anagrafica arr,string n, string c,int chiave)
{
arr.codifica(n,c,chiave);
}
that i re-arranged this way
void cod (anagrafica &arr,string n, string c,int chiave)
{
arr.codifica(n,c,chiave);
}
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 :
In a previous version the following method :
void anagrafica::stampa()
{
cout<<" nome cifrato "<<nome_cifrato;
cout<<" cognome cifrato "<<cognome_cifrato<<endl;
}
I had to modify in this new version :
void anagrafica::stampa()
{
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.
modified 10-Sep-22 3:10am.
|
|
|
|
|
Roberto64_Ge wrote: 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?
Regards
|
|
|
|
|
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
|
|
|
|
|
Very interesting, but you forgot to ask a question.
|
|
|
|
|
C++ doesn't have get and set , although you can provide functions with those names. Are you sure this isn't supposed to be C#?
But in the greater scheme of things, it sounds like you're asking for someone to do your assignment, which is something that rarely happens on this site, and certainly not for something of this size.
|
|
|
|
|
Coding?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
QStringList params = QStringList() << "qterminal" << "-e" << "bluetoothctl help"
The rude tone of your question would not have deserved an answer but maybe you'll learn to be polite.
Mircea
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
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
|
|
|
|
|
Member 14968771 wrote: The att6ached code is being posted here because
it is C++ code No, it has nothing to do with C++, it is purely a QT/qterminal issue. And this is the C/C++ forum.
In your code ...
QString exec = "qterminal";
QStringList params = QStringList() << "qterminal" << "-e" << "bluetoothctl" ; processTERMINAL->start(exec, params);
... you are passing "qterminal" as the first parameter to "qterminal" . So remove that field from your params .
And that is still not a C++ issue.
modified 5-Sep-22 4:30am.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Did you try to compare your these two "usages" to see the difference between them?
|
|
|
|
|
|
Quote: 1. I thought 'foreach" was a C++ "feature" - in QT doc they call it macro "Q_FOREACH" -
not sure which way is up... Then you were wrong. C++ has NO foreach construct, however, it provides the range-based for , see Range-based for loop (since C++11) - cppreference.com[^].
Quote: 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 QString s, then you could use the C++ range-based for .
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
You are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
QString offers a standard C++ iterator: QString Class | Qt Core 6.3.2[^]. So (assuming qstr is the reference to your string) you can try something like:
for (QString::iterator it = qstr->begin(); it != qstr->end(); ++it)
{
}
|
|
|
|
|
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
|
|
|
|
|
Roberto64_Ge wrote: 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.
You can do this on the ubuntu command line using
g++ -Wall -Wextra main.cpp header.cpp -o main or alternatively
g++ -Wall -Wextra -c main.cpp
g++ -Wall -Wextra -c header.cpp
g++ main.o header.o -o main 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.
Keep Calm and Carry On
|
|
|
|
|
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?
|
|
|
|
|
If you've created a VS C++ project, it knows how to deal with files that you add to the project. All you should need to do for a simple project is hit Build, and the IDE will take care of the rest.
Keep Calm and Carry On
|
|
|
|
|
Ok I tried and I did it. I right clicked on header.cpp and it gave the option to compile. This created the header.obj. Then I right clicked on the main.cpp and again I had the option to compile it and this generated the exe. Before doing all this I included in the main.cpp only header.h,
Now it works. Thanks for the clear explanation
|
|
|
|