-
February 16th, 2014, 03:56 PM
#1
(IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unresolved
I am working on a assignment for school and I am having some issues i havnetbeen able to figure out
my first issue is that i keep getting these external errors and then my cout stopped working, i understand im supposed to overload them or something but I dont really understand how
-
February 16th, 2014, 04:44 PM
#2
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Firstly, please don't post screen shots unless asked. We can't easily copy and paste the code into our own systems from them. Just do a normal copy and paste of code and then use code tags around the code (Go advanced, select the code and click '#').
st1 is an instance of the class Student. The class function getID() doesn't actually get the id but displays the value to the cout stream and has a return type of void. This is about what the compiler is complaining. Either call st1.getID() directly to display the value - or better have getID() return the value which is what would be expected from the name of the function. ie
Code:
int Student::getID()
{
return ID;
}
The same comment also applies to the getName() class function.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 16th, 2014, 05:54 PM
#3
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Thank you, for the quick responce and i managed to fix the cout issue but any ideas on fixing the external errors?
-
February 16th, 2014, 06:04 PM
#4
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Originally Posted by tato1993
Thank you, for the quick responce and i managed to fix the cout issue but any ideas on fixing the external errors?
What type of project did you create?
-
February 16th, 2014, 06:05 PM
#5
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Also here is the code
this is the Student.h
Code:
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
class Student
{private:
string fname;
string lname;
int ID;
public:
Student();
Student(string first,string last, int ID_num);
static int numberOfStudents;
void getName();
int getID();
};
Here is my Student.cpp
Code:
#include <iostream>
#include "Student.h"
#include <string>
using namespace std;
Student::Student()
{numberOfStudents+=1;
}
Student::Student(string first, string last, int ID_num)
{fname=first;
lname=last;
ID=ID_num;
numberOfStudents+=1;}
int Student::numberOfStudents=0;
void Student::getName()
{cout<<fname<<lname;}
int Student::getID()
{return ID;}
void main()
{
Student st1("Hakan", "Haberdar", 1234), st2("Charu", "Hans", 2345), st3("Tarikul", "Islam", 5442), st4;
cout << "We created " << Student::numberOfStudents << " student objects." << endl;
st1.getID();
cout<< " ";
st1.getName() ;
cout<< endl;
st2.getID() ;
cout<< " " ;
st2.getName();
cout<<endl;
st3.getID();
cout<< " " ;
st3.getName();
cout<< endl;
st4.getID();
cout<< " ";
st4.getName();
cout<< endl;
system("pause");
}
-
February 16th, 2014, 06:06 PM
#6
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Win 32 console Application
-
February 16th, 2014, 06:28 PM
#7
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
It looks like the linker can't find your main() function. You have main returning a type void but it should return a type int.
Your code compiles and links OK for me using MSVS - so it's probably how a linker property has been set.
Also <string.h> should be <cstring> in c++.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 16th, 2014, 09:16 PM
#8
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Idk if i should start a new thread but i ran into a new problem i tried creating a new class derived from this student class in its own .h, but whenever I use
Code:
#include "Student.h"
it tells me it cant open the source code.
Also im assuming my problem with the LNK is jus something on my version i got Microsoft Visual C++ 2010
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|