I'm a completely new to C++ and I'm having a very stupid problem.
I have a Graph class and I need to create a copy constructor for it. This is my class:
#include <igraph.h>
#include <iostream>
using namespace std;
class Graph {
public:
Graph(int N); // contructor
~Graph(); // destructor
Graph(const Graph& other); // Copy constructor
igraph_t * getGraph();
int getSize();
private:
igraph_t graph;
int size;
};
There's a function int igraph_copy(igraph_t * to, const igraph_t * from)
in igraph.h
that copies an igraph_t
type adequately.
The constructor and destructor are trivial and work normally, and I have the following copy constructor:
Graph :: Graph(const Graph& other) {
igraph_t * otherGraph = other.getGraph();
igraph_copy(&graph, otherGraph);
size = other.getSize();
}
igraph_t * Graph :: getGraph(){
return &graph;
}
int Graph :: getSize() {
return size;
}
When I compile this, I got the following errors:
calsaverini@Ankhesenamun:~/authC/teste$ make
g++ -I/usr/include/igraph -L/usr/local/lib -ligraph -c foo.cpp -o foo.o
foo.cpp: In copy constructor ‘Graph::Graph(const Graph&)’:
foo.cpp:30: error: passing ‘const Graph’ as ‘this’ argument of ‘igraph_t* Graph::getGraph()’ discards qualifiers
foo.cpp:32: error: passing ‘const Graph’ as ‘this’ argument of ‘int Graph::getSize()’ discards qualifiers
make: *** [foo.o] Error 1
I feel this must be something very basic I didn't get about what the const qualifier means.
I don't really know C++ (and I really don't know C that much deeply, for that matter...) but I need to mess with code made by people who do. :(
Any clues or remarks about this copy constructor will be also very humbly appreciated. :P