【发布时间】:2014-11-29 12:36:40
【问题描述】:
我的代码:
方块世界.hpp
#ifndef BLOCKYWORLD_H
#define BLOCKYWORLD_H
#include <CImg.h>
namespace logic {
class BlockyWorld {
public:
BlockyWorld( const CImg<float>* heightmap );
};
}
#endif // BLOCKYWORLD_H
方块世界.cpp
#include "BlockyWorld.hpp"
namespace logic {
BlockyWorld::BlockyWorld( const CImg<float>* heightmap ) {}
}
main.cpp
#include <CImg.h>
#include "logic/BlockyWorld.hpp"
//...
CImg<float> heigthMap;
logic::BlockyWorld world( &heigthMap );
//...
编译时遇到很多错误:
main.cpp:
include\logic\blockyworld.hpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
include\logic\blockyworld.hpp(9): error C2143: syntax error : missing ',' before '<'
main.cpp(85): error C2664: 'logic::BlockyWorld::BlockyWorld(const logic::BlockyWorld &)' : cannot convert argument 1 from 'cimg_library::CImg<float>' to 'const int'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
BlockyWorld.hpp & cpp
include\logic\blockyworld.hpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
include\logic\blockyworld.hpp(9): error C2143: syntax error : missing ',' before '<'
include\logic\blockyworld.cpp(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
include\logic\blockyworld.cpp(4): error C2143: syntax error : missing ',' before '<'
我不认为这是一个循环包含错误,有时会导致我出现此类错误=)。 我必须定义构造函数错误,或者我定义实现错误?正在寻找大约一个小时的答案,所以我现在真的会使用一个解释。
澄清一下 - 我不是初学者 c/c++ 程序员,但这些模板令人困惑:(
祝您有美好的一天,感谢您的回答。
【问题讨论】:
-
BlockyWorld::BlockyWorld( const CImg<float>& heightmap )与声明的签名不匹配:BlockyWorld( const CImg<float>* heightmap )! -
输入问题时出错=)
-
CImg的定义在哪里?
-
您确定
CImg类不在cimg或cimg_library命名空间中吗?来自here 的示例似乎正在使用using namespace cimg_library;
标签: c++ templates visual-c++