2 Attachment(s)
(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
Attachment 32381 Attachment 32379
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
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.
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?
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Quote:
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?
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");
}
Re: (IntelliSense: no operator "<<" matches these operands ) and LNK1120/2001 unreso
Win 32 console Application
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++.
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