You use a forward declaration when you need a complete type.
You must have a full definition of the class in order to use it.
The usual way to go about this is:
1) create a file Cat_main.h
2) move
#include <string> class Cat { public: Cat(std::string str); // Variables std::string name; // Functions void Meow(); };
to Cat_main.h
. Note that inside the header I removed using namespace std;
and qualified string with std::string
.
3) include this file in both Cat_main.cpp
and Cat.cpp
:
#include "Cat_main.h"
Related Posts:
- What is the difference between private and protected members of C++ classes?
- C++ [Error] no matching function for call to
- How do I define string constants in C++?
- C++ – No appropriate default constructor available
- G++ undefined reference to class::function
- What is predicate in C++?
- Understanding Python super() with __init__() methods [duplicate]
- Is it possible to make abstract classes in Python?
- Expression must have class type
- When should you use a class vs a struct in C++?
- Using two CSS classes on one element
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Why is enum class preferred over plain enum?
- How to assign multiple classes to an HTML container?
- What does ‘super().__init__()’ mean in python 3.x?
- How to assign multiple classes to an HTML container?
- Why am I getting this redefinition of class error?
- Single class has a Class Redefinition Error
- C++ Linked List Node with class
- (->) arrow operator and (.) dot operator , class pointer
- Python: How do I make a subclass from a superclass?
- Separating class code into a header and cpp file
- how to define -std=c++11 as default in g++
- Pointer to incomplete class type is not allowed
- Why am I getting this redefinition of class error?
- Difference between ‘cls’ and ‘self’ in Python classes?
- no default constructor exists for class
- Getting error “a nonstatic member reference must be relative to a specific object” while both member are in the same class
- Error “C++ requires a type specifier for all declarations whilst defining methods”
- What are the differences between struct and class in C++?
- error C2011: ” : ‘class’ type redefinition
- The compiler is complaining about my default parameters?
- C++ Linked List Node with class
- Getting error: ISO C++ forbids declaration of with no type
- “used without template parameters”
- expected constructor, destructor, or type conversion before ‘(’ token
- C++ Class ‘undeclared identifier”
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Base class undefined
- Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?
- What is the meaning of a C++ Wrapper Class?
- Does C++11 have C#-style properties?
- Update GCC on OSX
- Creating an instance of class
- How do you implement a class in C?
- uml classdiagram constructor with parameters
- expected primary-expression before ‘]’ token
- Does C have classes?
- Is there a way to compile C++ to C Code?
- error C2039: ‘string’ : is not a member of ‘std’, header file problem
- istream and ostream problem – C++
- Struct with template variables in C++
- error: no member function declared in class
- Here is some error with my .h file which show [Error] unterminated #ifndef when I include my class template in it
- Error: invalid use of member in static member function
- What does the variable $this mean in PHP?
- convert a char* to std::string
- system(“pause”); – Why is it wrong?
- How to use setprecision in C++
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Easiest way to convert int to string in C++
- pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
- C++ Singleton design pattern
- How to concatenate a std::string and an int
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- What is the significance of return 0 in C and C++?
- C++ error: terminate called after throwing an instance of ‘std::bad_alloc’
- error : expected unqualified-id before return in c++
- math in java – what does ” %” do?
- Algorithms in O(n^2) vs O(n) [duplicate]
- Unsigned keyword in C++
- Exception Handling in C++ Terminate called after throwing an instance of ‘char const*’
- How to deal with bad_alloc in C++?
- What causes signal ‘SIGILL’?
- “g++” is not recognized as an internal or external command, MinGW
- Is there a function to copy an array in C/C++?
- Sleep function in C++
- Division in C++
- How to iterate over a vector?
- Read data from a file into an array – C++
- Unknown override specifier, missing type specifier
- error: overloaded ‘operator<<' must be a binary operator (has 3 parameters)
- Process returned -1073741571 (0xC00000FD) on my c++ code
- Implementation of Vector in C++
- C++ Why Is There “Unknown Type” When Class Header is Included?
- Nested For – Loops to create multiplication table C++
- What is the difference between clang (and LLVM) and gcc / g++?
- The system cannot find the file specified. in Visual Studio
- bit vectors in c++
- to_string not declared in scope
- OpenCV Error: Assertion failed (size.width>0 && size.height>0) simple code
- Is there a C++ equivalent to getcwd?
- What is the return type of sizeof operator?
- C++ 2d char array to string
- Error: member function may not be declared outside of its class.
- C++ Signed/unsigned mismatch
- What does _T stands for in a CString
- mysql.h file can’t be found
- Getting an error “fopen’: This function or variable may be unsafe.” when compling [duplicate]
- What’s the difference between integer class and numeric class in R