You are not logged in.
Pages: 1
good afternoon all,
i have a c++ file, that makes error messages, when i compile it with g++ ... here is the complete text
#include <iostream>
using namespace std;
string str1, str2, str3, str4, str5, str6 ;
int edit_number ;
string edit_text ;
class contact {
private:
int account_id_number = 0 ; // muss später mit linux bash und datei dazu geregelt werden. linux bash befehl zum zählen und finden von lücken
string vorname ;
string nachname ;
string email_address ;
string discord_name ;
string twitter_name ;
string facebook_name ;
public:
void create (string vorname, string nachname, string email_address, string discord_name, string twitter_name, string facebook_name)
{
cout << "Gib eine Email-Addresse der neuen Person an: " << endl ;
cin >> email_address ;
cout << "Gib Vornamen und Nachnamen an: " << endl ;
cout << "Vorname:" ;
cin >> vorname ;
cout << "Nachname: " << endl ;
cin >> nachname ;
cout << "Gib den discord-namen der person an: " << endl ;
cin >> discord_name ;
cout << "Gib den twitter-namen der person an: " << endl ;
cin >> twitter_name ;
cout << "Gib den facebook-namen der person an: " << endl ;
cin >> facebook_name ;
// email_address.create vom prinzip her, aber wie wird es geschrieben?
} ; // erstellt eine person
void edit(string){
} ; // ändert ein auswählbares element einer auswählbaren person in einen eintrag um, den der benutzer eingibt
void delete(){
} ; // löscht eine person aus den daten
void display(){
} ; // zeigt die daten einer auswählbaren person an
void sort(){
} ; // sortiert personen so, dass lücken von account_id_number gefüllt werden
} ;
int main(){
int number_of_function = 0 ;
cout << "Gib eine Nummer für eine Funktion ein: ... " << endl ;
cout << "1. create , 2. edit , 3. delete , 4. display , 5. sort " << endl ;
cin >> number_of_function ;
switch (number_of_function)
{
case 1:
contact::create(string str1, str2, str3, str4, str5, str6);
break ;
case 2:
break ;
case 3:
break ;
case 4:
break ;
case 5:
break ;
default:
cout << "Diese Eingabe war falsch. " << endl ;
}
return 0 ;
}
do you know, where the errors are?
i have this error message
205 - 2 .cpp incomplete.cpp:43:10: error: expected unqualified-id before »delete«
43 | void delete(){
| ^~~~~~
205 - 2 .cpp incomplete.cpp: In function »int main()«:
205 - 2 .cpp incomplete.cpp:65:32: error: expected primary-expression before »str1«
65 | contact::create(string str1, str2, str3, str4, str5, str6);
| ^~~~Offline
there's so much so wrong ... where did you got this from?
also: your intented edit function has already flawed base logic - you don't want to give a string a member selector but a setter for every member
Offline
"delete" is a reserved keyword, don't use that as function name, try "remove()"
Offline
i have another question. here is another incomplete code
#include <iostream>
using namespace std ;
string contact_to_edit ; //this string should contain the email address from an contact, that the user want to edit
class {
email
name
}
void edit_contact(){
cout << "which email-address belongs to the contact, that you want edit?" << endl ;
cin >> contact_to_edit ;
cout << contact_to_edit.name ; // here is the problem. the variable "contact_to_edit" contains the email address, that the user want to edit. how can i write this so, that left to the point is the contained email address ? edit thx to posts above. after i renamed the function "delete", i have less error messages, but i have error messages left.
Last edited by lo7777799 (Yesterday 15:38:16)
Offline
where did you got this from?
Also what are you trying to achieve here? Have you ever written any C-code? Are we maybe doing your homework?
Offline
do you know, where the errors are?
Thease errors are because the program is not a valid C++ program.
205 - 2 .cpp incomplete.cpp:43:10: error: expected unqualified-id before »delete«
43 | void delete(){As noted above, delete is a reserved keyword and cannot be used as a function name.
205 - 2 .cpp incomplete.cpp:65:32: error: expected primary-expression before »str1«
65 | contact::create(string str1, str2, str3, str4, str5, str6);1. Function arguments are a comma-separated list of expressions (variables). There should be no type at the beginning of argument list.
2. You are trying to call create() as a static member function of class contact but it is not a static member function. You should create instance of contact first.
Although these are not all the problems in this program, there are some others...
Offline
Are we maybe doing your homework?
kinda looks like it
@OP
if you want to learn programming for your own joy - i recommend start with an easier to learn language - there're plenty, i personal recommend java or php - but python is said to be a good beginners language, too
the C family is quite rough - i just recently started learn them - and even with 15 years of experience and understanding what the books try to teach me it's quite a different level of what i'm used to
if you're a student ... we don't do your homework ... unless you offer us some compensation
Offline
ok, i found a lot of errors.
but what is wrong in line 65, i quote that code
contact::create(string str1, str2, str3, str4, str5, str6) ; and i want learn c++, not the slow python or php
Last edited by lo7777799 (Yesterday 17:15:15)
Offline
ok, i found a lot of errors.
but what is wrong in line 65, i quote that codecontact::create(string str1, str2, str3, str4, str5, str6) ;and i want learn c++, not the slow python or php
Remove string from the method call:
contact::create(str1, str2, str3, str4, str5, str6);Mainboard: GIGABYTE B550 AORUS ELITE V2 | CPU: Ryzen 7 5800X | RAM: 32 GB
GPU: GeForce RTX 4060 8 GB (580.119.02 proprietary) | Display: BenQ BL2405 1920x1080
Kernel: 6.18.8 stable | Boot Manager: GRUB2 | DE: KDE Plasma | Login Manager: SDDM | Compositor: KWin
Offline
ok, here is my new code
#include <iostream>
using namespace std;
int account_id_number ;
string str1 ;
string str2 ;
string str3 ;
string str4 ;
string str5 ;
string str6 ;
int edit_number ;
string edit_text ;
class contact {
private:
int account_id_number = 0 ; // muss später mit linux bash und datei dazu geregelt werden. linux bash befehl zum zählen und finden von lücken
string vorname ;
string nachname ;
string email_address ;
string discord_name ;
string twitter_name ;
string facebook_name ;
public:
int create (string vorname, string nachname, string email_address, string discord_name, string twitter_name, string facebook_name)
{
::contact::contact (email_address, vorname, nachname, discord_name, twitter_name, facebook_name) ;
return 0 ;
} ; // erstellt eine person
void edit(){
} ; // ändert ein auswählbares element einer auswählbaren person in einen eintrag um, den der benutzer eingibt
void delete_contact(){
} ; // löscht eine person aus den daten
void display(){
} ; // zeigt die daten einer auswählbaren person an
void sort(){
} ; // sortiert personen so, dass lücken von account_id_number gefüllt werden
} ;
int main(){
int number_of_function = 0 ;
cout << "Gib eine Nummer für eine Funktion ein: ... " << endl ;
cout << "1. create , 2. edit , 3. delete , 4. display , 5. sort " << endl ;
cin >> number_of_function ;
switch (number_of_function)
{
case 1:
cout << "Gib eine Email-Addresse der neuen Person an: " << endl ;
cin >> str3 ;
cout << "Gib Vornamen und Nachnamen an: " << endl ;
cout << "Vorname:" ;
cin >> str1 ;
cout << "Nachname: " << endl ;
cin >> str2 ;
cout << "Gib den discord-namen der person an: " << endl ;
cin >> str4 ;
cout << "Gib den twitter-namen der person an: " << endl ;
cin >> str5 ;
cout << "Gib den facebook-namen der person an: " << endl ;
cin >> str6 ;
// email_address.create vom prinzip her, aber wie wird es geschrieben?
contact() ;
break ;
case 2:
break ;
case 3:
break ;
case 4:
break ;
case 5:
break ;
default:
cout << "Diese Eingabe war falsch. " << endl ;
} ;
return 0 ;
}my error message is now
205 - 2 .cpp incomplete.cpp: In member function »int contact::create(std::string, std::string, std::string, std::string, std::string, std::string)«:
205 - 2 .cpp incomplete.cpp:30:26: error: Konstruktor »contact::contact« kann nicht direkt aufgerufen werden [-fpermissive]
30 | contact::contact (email_address, vorname, nachname, discord_name, twitter_name, facebook_name) ;
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205 - 2 .cpp incomplete.cpp:30:26: note: um eine funktionsartige Umwandlung zu erreichen, entfernen Sie das redundante »::contact«
205 - 2 .cpp incomplete.cpp:30:26: error: keine passende Funktion für Aufruf von »contact::contact(std::string&, std::string&, std::string&, std::string&, std::string&, std::string&)«
• es gibt 3 Kandidaten
• Kandidat 1: »constexpr contact::contact()«
205 - 2 .cpp incomplete.cpp:17:7:
17 | class contact {
| ^~~~~~~
• Kandidat erwartet 0 Argumente, 6 angegeben
• Kandidat 2: »constexpr contact::contact(const contact&)«
• Kandidat erwartet 1 Argument, 6 angegeben
• candidate 3: »constexpr contact::contact(contact&&)«
• Kandidat erwartet 1 Argument, 6 angegebenLast edited by lo7777799 (Yesterday 17:53:39)
Offline
you cannot call a constructor like a normal function, constructors are only called when an object is created, you don’t even have a constructor with parameters,
You’re kinda trying to use create() like “create a contact by calling the constructor inside the function” ![]()
"Nothing matters" -a Nihilist
"Why bother thinking what matters?" -me
Offline
hello, its me again.
i have corrected all fails in my text, now the compiler shows no error messages again
#include <iostream>
using namespace std;
int account_id_number ;
string str1 ;
string str2 ;
string str3 ;
string str4 ;
string str5 ;
string str6 ;
int edit_number ;
string edit_text ;
class contact
{
private:
int account_id_number = 0 ; // muss später mit linux bash und datei dazu geregelt werden. linux bash befehl zum zählen und finden von lücken
string vorname ;
string nachname ;
string email_address ;
string discord_name ;
string twitter_name ;
string facebook_name ;
public:
int create()
{
::contact();
return 0 ;
} ;
contact()
{
vorname = str1 ;
nachname = str2 ;
email_address = str3 ;
discord_name = str4 ;
twitter_name = str5 ;
facebook_name = str6 ;
} ;
; // erstellt eine person
void edit(){
} ; // ändert ein auswählbares element einer auswählbaren person in einen eintrag um, den der benutzer eingibt
void delete_contact(){
} ; // löscht eine person aus den daten
void display(){
} ; // zeigt die daten einer auswählbaren person an
void sort(){
} ; // sortiert personen so, dass lücken von account_id_number gefüllt werden
} ;
int main(){
int number_of_function = 0 ;
cout << "Gib eine Nummer für eine Funktion ein: ... " << endl ;
cout << "1. create , 2. edit , 3. delete , 4. display , 5. sort " << endl ;
cin >> number_of_function ;
switch (number_of_function)
{
case 1:
cout << "Gib eine Email-Addresse der neuen Person an: " << endl ;
cin >> str3 ;
cout << "Gib Vornamen und Nachnamen an: " << endl ;
cout << "Vorname:" ;
cin >> str1 ;
cout << "Nachname: " << endl ;
cin >> str2 ;
cout << "Gib den discord-namen der person an: " << endl ;
cin >> str4 ;
cout << "Gib den twitter-namen der person an: " << endl ;
cin >> str5 ;
cout << "Gib den facebook-namen der person an: " << endl ;
cin >> str6 ;
// email_address.create vom prinzip her, aber wie wird es geschrieben?
contact() ;
break ;
case 2:
break ;
case 3:
break ;
case 4:
break ;
case 5:
break ;
default:
cout << "Diese Eingabe war falsch. " << endl ;
} ;
return 0 ;
}you can mark my thread, this thread as solved.
Offline
and i want learn c++
You can't learn C++ by trial and error. Read some book which explains basics of C++, step by step. If you don't understand how to instantiate an object and how to initialize its members, take a step back and learn it with simpler example.
Offline
Since apparently your first language is German, get a book like "C++ - Das umfassende Handbuch" by Torsten T. Will (Rheinwerk Verlag, ISBN 978-3-8362-9853-7) to learn C++ from the basics to advanced stuff.
Mainboard: GIGABYTE B550 AORUS ELITE V2 | CPU: Ryzen 7 5800X | RAM: 32 GB
GPU: GeForce RTX 4060 8 GB (580.119.02 proprietary) | Display: BenQ BL2405 1920x1080
Kernel: 6.18.8 stable | Boot Manager: GRUB2 | DE: KDE Plasma | Login Manager: SDDM | Compositor: KWin
Offline
and i want learn c++, not the slow python or php
nuff said
even with the recommended book you will have a long and hard way - but hey - who am i to tell you with 15-20 years of experience in several languages - it's up to you to accept it
Offline
and i want learn c++
There are many good C++ resources out there.
The reference at https://en.cppreference.com/ is very handy as it covers the basic language features.
As for books there is this Stack Overflow post which lists some good options.
There are some good online tutorials available maybe look at this one.
As always the search engine of your choice is your friend here.
Personally I recommend learning regular C first, as it is a much easier language and gives you a good foundation to learn C++ later on.
It also gives a lot of insight into why and how C++ does things the way it does.
int account_id_number ;
string str1 ;
string str2 ;
string str3 ;
string str4 ;
string str5 ;
string str6 ; You seem to have a lot of global variables. This is a well know beginner problem and leads to problems later on when the program becomes more complex.
You should try to build a mental model on how data flows through your program and declare variables at the point where they are needed.
Then you start passing the variables down the chain as needed. At this point you will realize that you want too bundle some of them together and this is the point where you use the language features (classes, structs etc).
This will come with experience and you will have to make these mistakes to learn to avoid them in the future.
Also setting your locale to one of the english ones makes searching for error messages a lot easier.
not the slow python or php
Execution speed at this stage should not be your first concern. Focus on the correctness of your program first. The slow part in your program is the human in the loop anyway.
Offline
I could list all the individual problems in your programme but it'd be beside the point. The real problem here is that you're going too fast; you need to properly familiarise yourself with the very basics before writing larger programmes, not just randomly change the code through blind trial-and-error in the vain hope it'll result in a good programme.
Also, I second what the unpronounceable lmn said: C is simpler and easier to learn than C++. Start with C. Some would even say that C is faster. :^)
"Don't comment bad code - rewrite it." - The Elements of Programming Style (1978), Brian W. Kernighan & P. J. Plauger, p. 144.
Offline
C is simpler and easier to learn than C++.
That's true, and understanding C is very helpfull to understand other languages. The same for understanding computer hardware to understand C itself. However, modern C++ is different from C, and haphazardly applying C experience to C++ may make things even worse.
A big problem in programming learning is that examples are detached from practical usage. Often they learn C++ classes without understanding why that classes are needed for, considering them as "advanced" C structs. However, something what requires struct in C, often can be implemented in C++ in a completely different way. I don't know description of that partucular assignment, but pretty sure it can be implemented without custom classes, just with standard library and STL containers. Only when capabilites of standard library are not enough or it becomes inconvenient, custom class creation should be introduced.
Offline
Next to reading a book covering the basics I'd recommend to pick some c++ code of an application you care about and mess around with it (patch features etc) - this way you'll get to study code in vivo, see how things generally look and are approached.
Then pick another codebase in case the first one was sub-par ![]()
Offline
Pages: 1