GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Ask a Question


Start Coding Today




Data Structures


Interview Experiences

C Programming

C++ Programming

Java Programming



Incorrect compiler error for my c++ program

I wrote a c++ program and submitted in geekforgeeks. But I am getting compiler error in geekforgeeks website. Same program is compiling fine in my laptop linux os. The errors are ridiculous. For e.g. when I am creating an object of a class then I am getting error "redefinition of class". Any idea to solve this issue.

The link for the program is.


asked Mar 22 by sachina

Where is your code?

1 Answer

This is because you might be tempted to un-comment the code of the graph class. You are not supposed to un-commnet. Just implement the logic as is asked.


class Graph
    int V;
    list<int> *adj;
public :
    Graph(int V);
    void addEdge(int v,int w);
    bool isCyclic();

/*You are required to complete this method*/
bool Graph :: isCyclic()
//Your code here

int main(){
    Graph g = new Graph();

If you try, this you get the error that you are mentioning. But if you just update the code at the line //Your code here, you do not get any error of that kind.

answered May 5 by harshitgarg