Home > Back-end >  Display function repeat define how to solve?
Display function repeat define how to solve?

Time:01-23

I'm writing a c + + practice, is in general structure. H file defines several class structure, and then points the CPP file, each class a CPP file,
Compile a single CPP files are compiled,
But when the last link to the wrong

The/usr/bin/ld:/debug/run. O: in function ` RPF: : RP_Graphics: : RP_Graphics () ':
Graphics. CPP: (. Text + 0 x0) : multiple definition of ` RPF: : RP_Graphics: : RP_Graphics () '; ./debug/graphics. O: graphics. CPP: (. Text + 0 x0) : first defined here

Basic types are RP_Graphics error, each function prompts the
This is what causes excuse me?
It's me. H and the structure of the CPP file with wrong?

CodePudding user response:

 
The namespace RPF
{
The class RP_Graphics
{
Private:
RP_Brush brush;//brush style
RP_Canvas * canvas;//operation canvas
Public:
RP_Graphics ();
RP_Graphics (RP_Canvas * canvas);
~ RP_Graphics ();

RP_Brush & amp; GetBrush ();//get brush, after can be directly modified

RP_Graphics drawPoint (const RP_Point & amp; Point) const;//draw point
RP_Graphics drawLine (const int size, const RP_Point * * point) const;//line
RP_Graphics drawRect (const RP_Rectangle & amp; The rect) const;//draw a rectangle
RP_Graphics fillRect (const RP_Rectangle & amp; The rect) const;//drawing filled rectangular
RP_Graphics methods like drawCircle (const RP_Rectangle & amp; The rect) const;//draw round
RP_Graphics fillCircle (const RP_Point & amp; Point, const uint32_t radius) const;//draw round
RP_Graphics drawPolygon (const int size, const RP_Point * * point) const;//draw polygons
RP_Graphics fillPolygon (const int size, const RP_Point * * point) const;//draw polygons

//draw the Canvas and the Image function
RP_Graphics the draw (RP_Canvas & amp; Canvas, const RP_Point & amp; The rect) const;
RP_Graphics the draw (RP_Canvas & amp; Canvas, const RP_Rectangle & amp; The rect) const;
RP_Graphics the draw (RP_Canvas & amp; Canvas, const RP_Rectangle & amp; R_rect, const RP_Point & amp; The rect) const;
RP_Graphics the draw (RP_Canvas & amp; Canvas, const RP_Rectangle & amp; R_rect, const RP_Rectangle & amp; D_rect) const;
};
}

This is. H file about RP_Graphics definition

CodePudding user response:

.h files because will be several references, so it have a duty to stop their work many times (repeat definition),
Consult system. H
Most have
# # ifndef _xx_h_
# define _xx_h_
Define something yourself
# endif
This kind of structure,
Imitate the,

CodePudding user response:

This made a
I found that if using g + + directly compile time no problem, as long as the single open compile connection problem again
G + + - Isrc/include - STD=c + + 11 - lstdc++ SRC/run. The CPP SRC/graphics. The CPP SRC/canvas. CPP SRC/image. The CPP SRC/game. The CPP -o main
This approach directly through
But I use a Makefile
First. CPP compiled into. O file, use the g + + - c
Then use the
G + + connection
Do certain problems
I write all the class declaration in a. H file

CodePudding user response:

You write the function implementation is also in the header file?
  • Related