#.tpp files
10 messages · Page 1 of 1 (latest)
When your question is answered use !solved or the button below to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
@rose fulcrum
Screenshots!
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
can you give the entire header file?
Row.tpp
// Row.tpp
template <typename T, size_t N>
Row<T, N>::Row() {
for (size_t i = 0; i < N; ++i) data[i] = T {};
}
// Constructor from initializer_list
template <typename T, size_t N>
Row<T, N>::Row(std::initializer_list<T> values)
{
*this = values; // Delegate to assignment operator
}
// Assignment from initializer_list
template <typename T, size_t N>
Row<T, N>& Row<T, N>::operator=(std::initializer_list<T> values)
{
// Copy from initializer_list using pointer/index (avoid range-for / auto)
const T* src = values.begin();
size_t count = values.size();
size_t i = 0;
for (; i < count && i < N; ++i) {
data[i] = src[i];
}
// Fill remaining with default if fewer provided
for (; i < N; ++i) data[i] = T {};
return *this;
}
// operator[] for element access for Row
template <typename T, size_t N>
T& Row<T, N>::operator[](int col) { return data[col]; }
template <typename T, size_t N>
const T& Row<T, N>::operator[](int col) const { return data[col]; }
// Accessor for size of the Row
template <typename T, size_t N>
int Row<T, N>::size() const { return static_cast<int>(N); }
// Dot product between Rows
template <typename T, size_t N>
T Row<T, N>::operator*(const Row<T, N>& other) const {
T sum = T {};
for (size_t i = 0; i < N; ++i)
sum += data[i] * other.data[i];
return sum;
}```
Row.h
#ifndef ROW_H
#define ROW_H
#include <initializer_list>
template <typename T, size_t N>
class Row
{
private:
// Data in this Row
T data[N];
public:
// Constructor of Row
explicit Row();
// Constructor of Row from initializer list
Row(std::initializer_list<T> values);
// Assignment from initializer list
Row& operator=(std::initializer_list<T> values);
// operator[] for element access for Row
T& operator[](int col);
const T& operator[](int col) const;
// Accessor for size of the Row
int size() const;
// Dot product between Rows
T operator*(const Row& other) const;
};
#include "Row.tpp"
#endif // ROW_H```
this suppose is not editable , due to the rules of homework, but cause an error
or vscode clang recognize it is an error
well how is the .tpp file supposed to know about the other file and that Row exists
i think there is no way