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;








-1















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;











share|improve this question






















  • 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 to st = Student(ML,MSV); or simpler Student st(ML,MSV);

    – πάντα ῥεῖ
    Mar 24 at 7:45


















-1















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;











share|improve this question






















  • 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 to st = Student(ML,MSV); or simpler Student st(ML,MSV);

    – πάντα ῥεῖ
    Mar 24 at 7:45














-1












-1








-1








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;











share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 to st = Student(ML,MSV); or simpler Student 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











  • @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 to st = Student(ML,MSV); or simpler Student 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













1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer

























  • The code is good but Student(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











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
);



);













draft saved

draft discarded


















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









2














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.






share|improve this answer

























  • The code is good but Student(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















2














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.






share|improve this answer

























  • The code is good but Student(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













2












2








2







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 10:07

























answered Mar 24 at 7:30









xryl669xryl669

1,7131329




1,7131329












  • The code is good but Student(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







  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript