g++ compiler and error undefined reference
i use linux and g++ compiler for cplusplus and i made a class called Command.h with Command.cpp. my code is below
main.cpp
#include <iostream>
#include <string>
#include <ctime>
#include "./people.h"
#include "./Command.h"
using namespace std;
int main() {
string CMD="";
cout << "Type Your Valid Command To Do Action"<<endl << " help To show help-Menunn";
bool ConTact(false);
BeGiN:
do{
cin >> CMD;
Cmd CODE(CMD);
}while((cin>>CMD));
while(!(cin>>CMD)){
cout << "Unvalid Input :)nn";
goto BeGiN;
}
}
and my Command.h
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Cmd{
public:
Cmd(string);
void Help();
private:
string _name;
};
and my Command.cpp:
#include <iostream>
#include <string>
#include "./Command.h"
Cmd::Cmd(string code ){
cout <<" hi n";
if(code =="help");//show help menu ;
else if(code=="add");//show add contact menu
else if(code=="rm"); // show remove contact menu
else if(code=="change"); //show change menu
else if(code=="ls"); //show list of types of contacts
else if(code=="ls-l"); //show list of favorit contact
else if(code=="ls-f"); //show list of family contact
else if(code=="ls-d"); //show list of friends contact
else if(code=="ls-fe"); //show list of female contact
else if(code=="ls-ma"); //show list of male contact
else if(code=="ls-best"); //show list of 10 best favorite contact
else if(code=="ls-last"); //show list of 10 lastest added contact
else if(code=="ls-d"); //show list of friends contact
}
when i typed g++ main.cpp in terminal a strange error occurred
/usr/bin/ld: /tmp/ccWpq3Ix.o: in function `main':
main.cpp:(.text+0xc6): undefined reference to
`Cmd::Cmd(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >)'
collect2: error: ld returned 1 exit status
what should i do??
i used visual studio code.
constructor
New contributor
add a comment |
i use linux and g++ compiler for cplusplus and i made a class called Command.h with Command.cpp. my code is below
main.cpp
#include <iostream>
#include <string>
#include <ctime>
#include "./people.h"
#include "./Command.h"
using namespace std;
int main() {
string CMD="";
cout << "Type Your Valid Command To Do Action"<<endl << " help To show help-Menunn";
bool ConTact(false);
BeGiN:
do{
cin >> CMD;
Cmd CODE(CMD);
}while((cin>>CMD));
while(!(cin>>CMD)){
cout << "Unvalid Input :)nn";
goto BeGiN;
}
}
and my Command.h
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Cmd{
public:
Cmd(string);
void Help();
private:
string _name;
};
and my Command.cpp:
#include <iostream>
#include <string>
#include "./Command.h"
Cmd::Cmd(string code ){
cout <<" hi n";
if(code =="help");//show help menu ;
else if(code=="add");//show add contact menu
else if(code=="rm"); // show remove contact menu
else if(code=="change"); //show change menu
else if(code=="ls"); //show list of types of contacts
else if(code=="ls-l"); //show list of favorit contact
else if(code=="ls-f"); //show list of family contact
else if(code=="ls-d"); //show list of friends contact
else if(code=="ls-fe"); //show list of female contact
else if(code=="ls-ma"); //show list of male contact
else if(code=="ls-best"); //show list of 10 best favorite contact
else if(code=="ls-last"); //show list of 10 lastest added contact
else if(code=="ls-d"); //show list of friends contact
}
when i typed g++ main.cpp in terminal a strange error occurred
/usr/bin/ld: /tmp/ccWpq3Ix.o: in function `main':
main.cpp:(.text+0xc6): undefined reference to
`Cmd::Cmd(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >)'
collect2: error: ld returned 1 exit status
what should i do??
i used visual studio code.
constructor
New contributor
1
Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
39 mins ago
CodeReview reviews working code, so this question is off-topic here. Try asking on stackoverflow.com instead.
– user673679
38 mins ago
@user673679 SO won't accept this question either.
– Mast
21 mins ago
add a comment |
i use linux and g++ compiler for cplusplus and i made a class called Command.h with Command.cpp. my code is below
main.cpp
#include <iostream>
#include <string>
#include <ctime>
#include "./people.h"
#include "./Command.h"
using namespace std;
int main() {
string CMD="";
cout << "Type Your Valid Command To Do Action"<<endl << " help To show help-Menunn";
bool ConTact(false);
BeGiN:
do{
cin >> CMD;
Cmd CODE(CMD);
}while((cin>>CMD));
while(!(cin>>CMD)){
cout << "Unvalid Input :)nn";
goto BeGiN;
}
}
and my Command.h
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Cmd{
public:
Cmd(string);
void Help();
private:
string _name;
};
and my Command.cpp:
#include <iostream>
#include <string>
#include "./Command.h"
Cmd::Cmd(string code ){
cout <<" hi n";
if(code =="help");//show help menu ;
else if(code=="add");//show add contact menu
else if(code=="rm"); // show remove contact menu
else if(code=="change"); //show change menu
else if(code=="ls"); //show list of types of contacts
else if(code=="ls-l"); //show list of favorit contact
else if(code=="ls-f"); //show list of family contact
else if(code=="ls-d"); //show list of friends contact
else if(code=="ls-fe"); //show list of female contact
else if(code=="ls-ma"); //show list of male contact
else if(code=="ls-best"); //show list of 10 best favorite contact
else if(code=="ls-last"); //show list of 10 lastest added contact
else if(code=="ls-d"); //show list of friends contact
}
when i typed g++ main.cpp in terminal a strange error occurred
/usr/bin/ld: /tmp/ccWpq3Ix.o: in function `main':
main.cpp:(.text+0xc6): undefined reference to
`Cmd::Cmd(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >)'
collect2: error: ld returned 1 exit status
what should i do??
i used visual studio code.
constructor
New contributor
i use linux and g++ compiler for cplusplus and i made a class called Command.h with Command.cpp. my code is below
main.cpp
#include <iostream>
#include <string>
#include <ctime>
#include "./people.h"
#include "./Command.h"
using namespace std;
int main() {
string CMD="";
cout << "Type Your Valid Command To Do Action"<<endl << " help To show help-Menunn";
bool ConTact(false);
BeGiN:
do{
cin >> CMD;
Cmd CODE(CMD);
}while((cin>>CMD));
while(!(cin>>CMD)){
cout << "Unvalid Input :)nn";
goto BeGiN;
}
}
and my Command.h
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Cmd{
public:
Cmd(string);
void Help();
private:
string _name;
};
and my Command.cpp:
#include <iostream>
#include <string>
#include "./Command.h"
Cmd::Cmd(string code ){
cout <<" hi n";
if(code =="help");//show help menu ;
else if(code=="add");//show add contact menu
else if(code=="rm"); // show remove contact menu
else if(code=="change"); //show change menu
else if(code=="ls"); //show list of types of contacts
else if(code=="ls-l"); //show list of favorit contact
else if(code=="ls-f"); //show list of family contact
else if(code=="ls-d"); //show list of friends contact
else if(code=="ls-fe"); //show list of female contact
else if(code=="ls-ma"); //show list of male contact
else if(code=="ls-best"); //show list of 10 best favorite contact
else if(code=="ls-last"); //show list of 10 lastest added contact
else if(code=="ls-d"); //show list of friends contact
}
when i typed g++ main.cpp in terminal a strange error occurred
/usr/bin/ld: /tmp/ccWpq3Ix.o: in function `main':
main.cpp:(.text+0xc6): undefined reference to
`Cmd::Cmd(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >)'
collect2: error: ld returned 1 exit status
what should i do??
i used visual studio code.
constructor
constructor
New contributor
New contributor
New contributor
asked 43 mins ago
mohammadreza khorasani
1
1
New contributor
New contributor
1
Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
39 mins ago
CodeReview reviews working code, so this question is off-topic here. Try asking on stackoverflow.com instead.
– user673679
38 mins ago
@user673679 SO won't accept this question either.
– Mast
21 mins ago
add a comment |
1
Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
39 mins ago
CodeReview reviews working code, so this question is off-topic here. Try asking on stackoverflow.com instead.
– user673679
38 mins ago
@user673679 SO won't accept this question either.
– Mast
21 mins ago
1
1
Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
39 mins ago
Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
39 mins ago
CodeReview reviews working code, so this question is off-topic here. Try asking on stackoverflow.com instead.
– user673679
38 mins ago
CodeReview reviews working code, so this question is off-topic here. Try asking on stackoverflow.com instead.
– user673679
38 mins ago
@user673679 SO won't accept this question either.
– Mast
21 mins ago
@user673679 SO won't accept this question either.
– Mast
21 mins ago
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
mohammadreza khorasani is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210493%2fg-compiler-and-error-undefined-reference%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
mohammadreza khorasani is a new contributor. Be nice, and check out our Code of Conduct.
mohammadreza khorasani is a new contributor. Be nice, and check out our Code of Conduct.
mohammadreza khorasani is a new contributor. Be nice, and check out our Code of Conduct.
mohammadreza khorasani is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210493%2fg-compiler-and-error-undefined-reference%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
39 mins ago
CodeReview reviews working code, so this question is off-topic here. Try asking on stackoverflow.com instead.
– user673679
38 mins ago
@user673679 SO won't accept this question either.
– Mast
21 mins ago