小编Joh*_*man的帖子

继承和memcpy - 它如何一起工作?

我有这个代码:

#include <iostream>
#include <string>
#include <cstring>

class Animal
{
public:
    Animal(const std::string &name) : _name(name)
    {
    }
    virtual void Print() const = 0;
    virtual ~Animal() {}
protected:
    std::string _name;
};

class Dog : public Animal
{
public:
    Dog(const std::string &name, const std::string &dogtype) : Animal(name), _dogtype(dogtype)
    {
        Print();
    }
    void Print() const
    {
        std::cout << _name << " of type " << _dogtype << std::endl;
    }
private:
    std::string _dogtype;
};

class Cat : public Animal
{
public:
    Cat(const std::string …
Run Code Online (Sandbox Code Playgroud)

c++ oop inheritance memcpy

2
推荐指数
1
解决办法
585
查看次数

对基础构造函数的未定义引用

可能重复:
G ++ Cpp中的"未定义引用"

我有这个标题

#ifndef TEST_H_
#define TEST_H_

class TEST
{
public :
    TEST();
};


#endif /* TEST_H_ */
Run Code Online (Sandbox Code Playgroud)

和这个标题

#ifndef TESTS_H_
#define TESTS_H_
#include "TEST.h"

class TESTS : public TEST
{
public :
    TESTS();
};


#endif /* TESTS_H_ */
Run Code Online (Sandbox Code Playgroud)

我实现了这样的标题:

#include <iostream>
using namespace std;
#include "TEST.h"
TEST:: TEST()
{
}
int main(int argc, char **argv) {
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

还有这个:

#include "TESTS.h"

TESTS :: TESTS() : TEST()
{
}


int main(int argc, char **argv) {
    return 0; …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance undefined-reference

1
推荐指数
1
解决办法
3684
查看次数

标签 统计

c++ ×2

inheritance ×2

memcpy ×1

oop ×1

undefined-reference ×1