I would like to obtain information from a text file and assign that information into class objectsWhy should the “PIMPL” idiom be used?Why does an overridden function in the derived class hide other overloads of the base class?Returning ints versus void“Undefined reference to” template class constructorWhy is 'int i = i;' legal?Turbo C++ and Code blocksFunction ambiguous in multiple inheritanceHow do I read from an input file after passing the ifstream object to a function?Passing Array of objects to same class C++a function-definition is not allowed here: void encryption(ifstream encrypt_file, ofstream keys_out, ofstream cipher_out) {
Are there situations when self-assignment is useful?
What are these arcade games in Ghostbusters 1984?
How to convert to standalone document a matrix table
General purpose replacement for enum with FlagsAttribute
How does an ARM MCU run faster than the external crystal?
Why does the 6502 have the BIT instruction?
What are the benefits of cryosleep?
How to capture more stars?
Crossing US border with music files I'm legally allowed to possess
Seed ship, unsexed person, cover has golden person attached to ship by umbilical cord
Were pens caps holes designed to prevent death by suffocation if swallowed?
I think I may have violated academic integrity last year - what should I do?
How many chess players are over 2500 Elo?
Why do airplanes use an axial flow jet engine instead of a more compact centrifugal jet engine?
How to make a crossed out leftrightarrow?
analysis of BJT PNP type - why they can use voltage divider?
Full backup on database creation
Why does the 'metric Lagrangian' approach appear to fail in Newtonian mechanics?
How can I get exact maximal value of this expression?
Is this resistor leaking? If so, is it a concern?
How can I translate "would" in "He had to run faster than his tribemate, as the hindmost would be eaten by the lion"?
How bitcoin nodes update UTXO set when their latests blocks are replaced?
At what point in European history could a government build a printing press given a basic description?
Full horizontal justification in table
I would like to obtain information from a text file and assign that information into class objects
Why should the “PIMPL” idiom be used?Why does an overridden function in the derived class hide other overloads of the base class?Returning ints versus void“Undefined reference to” template class constructorWhy is 'int i = i;' legal?Turbo C++ and Code blocksFunction ambiguous in multiple inheritanceHow do I read from an input file after passing the ifstream object to a function?Passing Array of objects to same class C++a function-definition is not allowed here: void encryption(ifstream encrypt_file, ofstream keys_out, ofstream cipher_out) {
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Why the compiler throw me error:invalid use of 'Student::Student'|
this is content file(ListOfStudent):1234 46567
this is my code:
class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()
vector<Student>ListOfStudent;
ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);
return 0;
Student::Student(string ML,string MSV)
this->ML=ML;
this->MSV=MSV;
c++ codeblocks
add a comment |
Why the compiler throw me error:invalid use of 'Student::Student'|
this is content file(ListOfStudent):1234 46567
this is my code:
class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()
vector<Student>ListOfStudent;
ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);
return 0;
Student::Student(string ML,string MSV)
this->ML=ML;
this->MSV=MSV;
c++ codeblocks
Please convert your code to a minimal reproducible example and post the complete error message from the compiler.
– R Sahu
Mar 24 at 7:29
@RSahu In what way is the question not an MCVE?
– john
Mar 24 at 7:38
You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.
– R Sahu
Mar 24 at 7:42
You cannot call the constructor via an instance.st.Student(ML,MSV);
should be changed tost = Student(ML,MSV);
or simplerStudent st(ML,MSV);
– πάντα ῥεῖ
Mar 24 at 7:45
add a comment |
Why the compiler throw me error:invalid use of 'Student::Student'|
this is content file(ListOfStudent):1234 46567
this is my code:
class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()
vector<Student>ListOfStudent;
ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);
return 0;
Student::Student(string ML,string MSV)
this->ML=ML;
this->MSV=MSV;
c++ codeblocks
Why the compiler throw me error:invalid use of 'Student::Student'|
this is content file(ListOfStudent):1234 46567
this is my code:
class Student
string ML,MSV;
public:
Student();
Student(string ML,string MSV );
~Student();
void Out();
;
int main()
vector<Student>ListOfStudent;
ifstream inf("ListOfStudentFile");
Student st;
while(inf)
string ML,MSV;
inf>>ML>>MSV;
st.Student(ML,MSV);
ListOfStudent.push_back(st);
return 0;
Student::Student(string ML,string MSV)
this->ML=ML;
this->MSV=MSV;
c++ codeblocks
c++ codeblocks
asked Mar 24 at 7:23
KanKan
295
295
Please convert your code to a minimal reproducible example and post the complete error message from the compiler.
– R Sahu
Mar 24 at 7:29
@RSahu In what way is the question not an MCVE?
– john
Mar 24 at 7:38
You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.
– R Sahu
Mar 24 at 7:42
You cannot call the constructor via an instance.st.Student(ML,MSV);
should be changed tost = Student(ML,MSV);
or simplerStudent st(ML,MSV);
– πάντα ῥεῖ
Mar 24 at 7:45
add a comment |
Please convert your code to a minimal reproducible example and post the complete error message from the compiler.
– R Sahu
Mar 24 at 7:29
@RSahu In what way is the question not an MCVE?
– john
Mar 24 at 7:38
You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.
– R Sahu
Mar 24 at 7:42
You cannot call the constructor via an instance.st.Student(ML,MSV);
should be changed tost = Student(ML,MSV);
or simplerStudent st(ML,MSV);
– πάντα ῥεῖ
Mar 24 at 7:45
Please convert your code to a minimal reproducible example and post the complete error message from the compiler.
– R Sahu
Mar 24 at 7:29
Please convert your code to a minimal reproducible example and post the complete error message from the compiler.
– R Sahu
Mar 24 at 7:29
@RSahu In what way is the question not an MCVE?
– john
Mar 24 at 7:38
@RSahu In what way is the question not an MCVE?
– john
Mar 24 at 7:38
You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.
– R Sahu
Mar 24 at 7:42
You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.
– R Sahu
Mar 24 at 7:42
You cannot call the constructor via an instance.
st.Student(ML,MSV);
should be changed to st = Student(ML,MSV);
or simpler Student st(ML,MSV);
– πάντα ῥεῖ
Mar 24 at 7:45
You cannot call the constructor via an instance.
st.Student(ML,MSV);
should be changed to st = Student(ML,MSV);
or simpler Student st(ML,MSV);
– πάντα ῥεῖ
Mar 24 at 7:45
add a comment |
1 Answer
1
active
oldest
votes
You can't call a constructor explicitely.
You should have written:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));
Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);
For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.
The code is good butStudent(ML,MSV)
is an explicit constructor call isn't it?
– john
Mar 24 at 7:36
1
The way Student is being constructed, emplace_back is the way to go I feel
– Hemil
Mar 24 at 8:26
yeah,my code was run,thank you so much for that
– Kan
Mar 25 at 4:39
add a comment |
Your Answer
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: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
);
);
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%2fstackoverflow.com%2fquestions%2f55321579%2fi-would-like-to-obtain-information-from-a-text-file-and-assign-that-information%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't call a constructor explicitely.
You should have written:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));
Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);
For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.
The code is good butStudent(ML,MSV)
is an explicit constructor call isn't it?
– john
Mar 24 at 7:36
1
The way Student is being constructed, emplace_back is the way to go I feel
– Hemil
Mar 24 at 8:26
yeah,my code was run,thank you so much for that
– Kan
Mar 25 at 4:39
add a comment |
You can't call a constructor explicitely.
You should have written:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));
Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);
For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.
The code is good butStudent(ML,MSV)
is an explicit constructor call isn't it?
– john
Mar 24 at 7:36
1
The way Student is being constructed, emplace_back is the way to go I feel
– Hemil
Mar 24 at 8:26
yeah,my code was run,thank you so much for that
– Kan
Mar 25 at 4:39
add a comment |
You can't call a constructor explicitely.
You should have written:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));
Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);
For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.
You can't call a constructor explicitely.
You should have written:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.push_back(Student(ML,MSV));
Following Hemil's suggestion and if you are using C++ 11, you can avoid constructing a temporary, via direct passing of constructor's arguments like this:
while(inf)
string ML,MSV;
inf>>ML>>MSV;
ListOfStudent.emplace_back(ML,MSV);
For a simple struct like yours, it should not make any difference anyway, so use whatever you prefer.
edited Mar 24 at 10:07
answered Mar 24 at 7:30
xryl669xryl669
1,7131329
1,7131329
The code is good butStudent(ML,MSV)
is an explicit constructor call isn't it?
– john
Mar 24 at 7:36
1
The way Student is being constructed, emplace_back is the way to go I feel
– Hemil
Mar 24 at 8:26
yeah,my code was run,thank you so much for that
– Kan
Mar 25 at 4:39
add a comment |
The code is good butStudent(ML,MSV)
is an explicit constructor call isn't it?
– john
Mar 24 at 7:36
1
The way Student is being constructed, emplace_back is the way to go I feel
– Hemil
Mar 24 at 8:26
yeah,my code was run,thank you so much for that
– Kan
Mar 25 at 4:39
The code is good but
Student(ML,MSV)
is an explicit constructor call isn't it?– john
Mar 24 at 7:36
The code is good but
Student(ML,MSV)
is an explicit constructor call isn't it?– john
Mar 24 at 7:36
1
1
The way Student is being constructed, emplace_back is the way to go I feel
– Hemil
Mar 24 at 8:26
The way Student is being constructed, emplace_back is the way to go I feel
– Hemil
Mar 24 at 8:26
yeah,my code was run,thank you so much for that
– Kan
Mar 25 at 4:39
yeah,my code was run,thank you so much for that
– Kan
Mar 25 at 4:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55321579%2fi-would-like-to-obtain-information-from-a-text-file-and-assign-that-information%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
Please convert your code to a minimal reproducible example and post the complete error message from the compiler.
– R Sahu
Mar 24 at 7:29
@RSahu In what way is the question not an MCVE?
– john
Mar 24 at 7:38
You can add the few missing pieces to make sure that the code can be compiled to produce the exact error you are seeing.
– R Sahu
Mar 24 at 7:42
You cannot call the constructor via an instance.
st.Student(ML,MSV);
should be changed tost = Student(ML,MSV);
or simplerStudent st(ML,MSV);
– πάντα ῥεῖ
Mar 24 at 7:45