Buckys C++ tutorial 42-Arrow selection operator.

0 Vikram Jayanthi · June 27, 2014
Cant figure out whats wrong! 
Code below:
main.cpp:
#include<iostream>
#include "Vikram.h"
using namespace std;
int main()
{


Vikram obj;
obj.printstuff();




}

//The header file
Vikram.h:
#ifndef VIKRAM_H
#define VIKRAM_H




class Vikram
{
    public:
        Vikram();
        void printstuff();
    protected:
    private:
};


#endif // VIKRAM_H


Vikram.cpp:
#include "Vikram.h"
#include<iostream>
using namespace std;
Vikram::Vikram()
{


}


void Vikram::printstuff()
{


  cout<<"Why wont this work??"<<endl;




}



The compiler says Undefined reference to Vikram::Vikram. 
and undefined reference to Vikram::printstuff;

Please reply. Thanks

Post a Reply

Replies

Oldest  Newest  Rating
+1 Mathias Frits Rørvik · June 27, 2014
Compiles and runs just find here. 
0 ebelos azuz · June 27, 2014
i did not look too long so there might be something else but it seems your missing a "   ;   " after your method.
0 Horacio Accipiter · June 27, 2014
How are you compiling this?

You need to compile both main.cpp and Vikram.cpp, and link them.

If you are using an IDE, put Vikram.cpp into your project.
0 Daniel Collier · June 27, 2014
no you are not messing (;) it should compile fine, please tells use what the error is
0 Vikram Jayanthi · June 28, 2014
It says undefined reference to Vikram::printstuff. But then I reloaded it 10 times and it worked. Code blocks is annoying.
  • 1

C++

107,021 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator